时间:2021-07-01 10:21:17 帮助过:13人阅读
1 --时间日期 2 SELECT ‘today‘‘s date is ‘+ CONVERT(VARCHAR(12), GETDATE(),102)AS da
1 SELECT GETDATE() 当前日期时间, 2 GETUTCDATE() ut日期时间, 3 DATEPART(YEAR, GETDATE()) 年, 4 DATENAME(YEAR, GETDATE()) 年名, 5 DATEPART(MONTH, GETDATE()) 月, 6 DATENAME(MONTH, GETDATE()) 月份名, 7 DATEPART(DAY, GETDATE()) 日, 8 DAY(GETDATE()) 日, 9 MONTH(GETDATE()) 月, 10 YEAR(GETDATE()) 年, 11 DATEADD(DAY, 5, GETDATE()) 新日期, 12 DATEDIFF(DAY, GETDATE(), ‘2018-12-17‘) AS 日期间隔;
1 --转换函数 cast(),convert() 2 SELECT CAST(‘2018‘ AS DECIMAL(10, 5)) AS deci, 3 CONVERT(VARCHAR, GETDATE(), 101) AS ‘101‘, 4 CONVERT(VARCHAR, GETDATE(), 102) AS ‘102‘, 5 CONVERT(VARCHAR, GETDATE(), 103) AS ‘103‘, 6 CONVERT(VARCHAR, GETDATE(), 104) AS ‘104‘, 7 CONVERT(VARCHAR, GETDATE(), 105) AS ‘105‘, 8 CONVERT(VARCHAR, GETDATE(), 106) AS ‘106‘, 9 CONVERT(VARCHAR, GETDATE(), 107) AS ‘107‘, 10 CONVERT(VARCHAR, GETDATE(), 108) AS ‘108‘, 11 CONVERT(VARCHAR, GETDATE(), 109) AS ‘109‘, 12 CONVERT(VARCHAR, GETDATE(), 100) AS ‘100‘, 13 CONVERT(VARCHAR, GETDATE(), 120) AS ‘120‘, 14 CONVERT(VARCHAR, GETDATE(), 121) AS ‘121‘, 15 CONVERT(VARCHAR, GETDATE(), 126) AS ‘126‘, 16 CONVERT(VARCHAR, GETDATE(), 130) AS ‘130‘; 17 18 19 --创建uniqueidentifier类型的唯一值 20 SELECT NEWID() AS Id 21 --ISNULL(c1,c2) 22 SELECT ISNULL(ParentId,‘########‘),* FROM dbo.Module 23 --isdate(exp)判断exp是否为有效日期 24 SELECT ISDATE(‘2018-12-11 12:2:1‘) 25 --ISNUMERIC(c1)判断c1是否是数字,是则返回1,否返回0 26 SELECT ISNUMERIC(‘1‘) 是,ISNUMERIC(‘a‘) 否
sqlserver常用函数
标签:lse str lower utc sci alt 系统 isnull char