可用如下sql语句:
select convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) day from (select '2015-07'+'-01' day) t1, (select number from MASTER..spt_values WHERE TYPE='P' AND number>=0 and number<=31) t2 where convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) like '2015-07%'
说明:要查询某年某月,只许将语句中的2015-07替换即可。
结果截图:
如果是查询某月某段时间内的连续天数,可以这样写:
SELECT * FROM (
select convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) day from(select '2015-09'+'-01' day) t1,(select number from MASTER..spt_values WHERE TYPE='P' AND number>=0 and number<=31) t2 where convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) like '2015-09%'
) T
WHERE T.day > '2015-09-05' AND T.day < '2015-09-15'
截图如下: