发布网友 发布时间:2022-04-08 10:54
共2个回答
懂视网 时间:2022-04-08 15:15
可用如下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‘
截图如下:
SQLServer用sql语句怎么返回一个月所有的天数
标签:
热心网友 时间:2022-04-08 12:23
SELECT date_format(crtime,'%Y-%m') as qq ,