根据日期类型字段获取年、季度、周(SQLSERVER)

SELECT     YEAR(CollectionDate) AS Year, DATEDIFF(quarter, CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) + 1 AS Quarter, DATEDIFF(week,CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) - DATEDIFF(quarter, CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) * 13 + 1 AS Week, CollectionDate
FROM         dbo.CollectionInformationList

根据日期类型字段获取年、季度、周(SQLSERVER),布布扣,bubuko.com

根据日期类型字段获取年、季度、周(SQLSERVER)

上一篇:SQL数据库数据类型详解


下一篇:利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能