如何求出给定时间当月每一天的日期?
例如给定一个时间为 “2012-05-08”,
希望得出当月每一天的日期,即结果为
2012-05-01
2012-05-02
2012-05-03
2012-05-04
2012-05-05
…………
2012-05-31
用SQL语句该如何写呢?
[解决办法]
DECLARE @DATE VARCHAR(10)SET @DATE = '2012-05-08'SELECT CONVERT(VARCHAR(10),DATEADD(DAY,number,LEFT(@DATE,8) + '01'),120) AS DateFROM master..spt_valuesWHERE type = 'P' AND (number BETWEEN 0 AND 32) AND DATEADD(DAY,number,LEFT(@DATE,8) + '01') < DATEADD(MONTH,1,LEFT(@DATE,8) + '01')Date2012-05-012012-05-022012-05-032012-05-042012-05-052012-05-062012-05-072012-05-082012-05-092012-05-102012-05-112012-05-122012-05-132012-05-142012-05-152012-05-162012-05-172012-05-182012-05-192012-05-202012-05-212012-05-222012-05-232012-05-242012-05-252012-05-262012-05-272012-05-282012-05-292012-05-302012-05-31