zoukankan      html  css  js  c++  java
  • SQL常用语句(不定期更新)包含 日期格式,取列

    select getdate()

    select dateadd(day,-10,getdate())

    select datepart(weekday,getdate())

    select @@datefirst
    select datepart(dw,getdate())

    set datefirst 1--设置周一为1

    select convert(datetime,convert(char(8),getdate(),120)+'1')--本月第一天
    select dateadd(day,-1,convert(char(8),dateadd(month,1,getdate()),120)+'1')--本月最后一天


    select CONVERT(varchar, getdate(), 120 )
    2004-09-12 11:06:08

    select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
    20040912110608

    convert(varchar(12),getdate(),23)
    2008-04-01

    select CONVERT(varchar(12) , getdate(), 111 )
    2004/09/12

    select CONVERT(varchar(12) , getdate(), 112 )
    20040912

    select CONVERT(varchar(12) , getdate(), 102 )
    2004.09.12

    其它不常用的日期格式转换方法:

    select CONVERT(varchar(12) , getdate(), 101 )
    09/12/2004

    select CONVERT(varchar(12) , getdate(), 103 )
    12/09/2004

    select CONVERT(varchar(12) , getdate(), 104 )
    12.09.2004

    select CONVERT(varchar(12) , getdate(), 105 )
    12-09-2004

    select CONVERT(varchar(12) , getdate(), 106 )
    12 09 2004

    select CONVERT(varchar(12) , getdate(), 107 )
    09 12, 2004

    select CONVERT(varchar(12) , getdate(), 108 )
    11:06:08

    select CONVERT(varchar(12) , getdate(), 109 )
    09 12 2004 1

    select CONVERT(varchar(12) , getdate(), 110 )
    09-12-2004

    select CONVERT(varchar(12) , getdate(), 113 )
    12 09 2004 1

    select CONVERT(varchar(12) , getdate(), 114 )
    11:06:08.177

    取列

    begin tran 
    declare @sql varchar(4000),@ff varchar(200)
    select @sql=''
    declare c1 cursor for 
    --select name from syscolumns where id=772965880
    --select a.name from syscolumns a,sysobjects b where b.name='KCCKD1' and a.id=b.id and b.type='U'
    select name from syscolumns where id = object_id('表名') 
    open c1
    fetch c1 into @ff 
    while @@fetch_status = 0 
    begin
    select @sql=@sql+','+ @ff
    fetch c1 into @ff
    end 
    close c1
    deallocate c1
    print '1'
    print @sql
    commit tran

  • 相关阅读:
    Python正则表达式指南
    emacs 常用命令与配置
    将代码转换为语法高亮的HTML
    UML 用例图
    Sql Server 2005函数学习(转)
    实现ASP.NET程序性能目标的几种方法转载http://www.wzsky.net/html/Program/net/39759.html
    浅淡SqlServer的Top与Oracle的RowNum 转载自http://www.cnblogs.com/liguangxi8/archive/2010/05/21/1740708.html
    存储过程权限和订单类别
    UrlRewrite(Url重写技术)
    Jquery ajax多级联动
  • 原文地址:https://www.cnblogs.com/txws1119/p/6003830.html
Copyright © 2011-2022 走看看