随机数
select cast(floor(rand()*10000) as int)
GUID
select newid()
判断两个日期是否为同一天
DATEDIFF(DAY,QsDate,'2016-01-26')=0
索引的自增长标识种子设置为guid格式(常规-默认值或绑定 && 数据类型=char(255))
LOWER(REPLACE(NEWID(),'-',''))
IF-ELSE语句
格式IF 条件表达式BEGIN SQL语句ENDELSE BEGIN SQL语句END
时间转化,如将 2016-03-11 13:00:10.880 转化为 20160311
select convert(varchar(20),DATEPART(YEAR,PayDate)) + RIGHT('00' + convert(varchar(20),DATEPART(MONTH,PayDate)),2) + RIGHT('00' + convert(varchar(20),DATEPART(DAY,PayDate)),2) from dbo.T001_HuaKouAmount
其他时间转化
SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSELECT CONVERT(varchar(100), GETDATE(), 1): 05/16/06SELECT CONVERT(varchar(100), GETDATE(), 2): 06.05.16SELECT CONVERT(varchar(100), GETDATE(), 3): 16/05/06SELECT CONVERT(varchar(100), GETDATE(), 4): 16.05.06SELECT CONVERT(varchar(100), GETDATE(), 5): 16-05-06SELECT CONVERT(varchar(100), GETDATE(), 6): 16 05 06SELECT CONVERT(varchar(100), GETDATE(), 7): 05 16, 06SELECT CONVERT(varchar(100), GETDATE(), 8): 10:57:46SELECT CONVERT(varchar(100), GETDATE(), 9): 05 16 2006 10:57:46:827AMSELECT CONVERT(varchar(100), GETDATE(), 10): 05-16-06SELECT CONVERT(varchar(100), GETDATE(), 11): 06/05/16SELECT CONVERT(varchar(100), GETDATE(), 12): 060516SELECT CONVERT(varchar(100), GETDATE(), 13): 16 05 2006 10:57:46:937SELECT CONVERT(varchar(100), GETDATE(), 14): 10:57:46:967SELECT CONVERT(varchar(100), GETDATE(), 20): 2006-05-16 10:57:47SELECT CONVERT(varchar(100), GETDATE(), 21): 2006-05-16 10:57:47.157SELECT CONVERT(varchar(100), GETDATE(), 22): 05/16/06 10:57:47 AMSELECT CONVERT(varchar(100), GETDATE(), 23): 2006-05-16SELECT CONVERT(varchar(100), GETDATE(), 24): 10:57:47SELECT CONVERT(varchar(100), GETDATE(), 25): 2006-05-16 10:57:47.250SELECT CONVERT(varchar(100), GETDATE(), 100): 05 16 2006 10:57AMSELECT CONVERT(varchar(100), GETDATE(), 101): 05/16/2006SELECT CONVERT(varchar(100), GETDATE(), 102): 2006.05.16SELECT CONVERT(varchar(100), GETDATE(), 103): 16/05/2006SELECT CONVERT(varchar(100), GETDATE(), 104): 16.05.2006SELECT CONVERT(varchar(100), GETDATE(), 105): 16-05-2006SELECT CONVERT(varchar(100), GETDATE(), 106): 16 05 2006SELECT CONVERT(varchar(100), GETDATE(), 107): 05 16, 2006SELECT CONVERT(varchar(100), GETDATE(), 108): 10:57:49SELECT CONVERT(varchar(100), GETDATE(), 109): 05 16 2006 10:57:49:437AMSELECT CONVERT(varchar(100), GETDATE(), 110): 05-16-2006SELECT CONVERT(varchar(100), GETDATE(), 111): 2006/05/16SELECT CONVERT(varchar(100), GETDATE(), 112): 20060516SELECT CONVERT(varchar(100), GETDATE(), 113): 16 05 2006 10:57:49:513SELECT CONVERT(varchar(100), GETDATE(), 114): 10:57:49:547SELECT CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49SELECT CONVERT(varchar(100), GETDATE(), 121): 2006-05-16 10:57:49:000
Case语法
SELECT a.*,b.MaxAmount FROM tableA a join tableB b ON b.Vaieity = (case a.DateForm when '预付款' then 'a' when '公户清算金额' then 'a' when '私户清算金额' then 'b' end) WHERE QsFlag = '0'