Sql Server 查询某月有多少天
select number from MASTER..spt_values WHERE TYPE='P' AND number>=1 and number<=day(dateadd(day,-1, dateadd(MONTH, 1,'2021-08-01 15:36:13.340')))
select number from MASTER..spt_values WHERE TYPE='P' AND number>=1 and ( (cast(year(GETDATE()) as varchar(6)) +cast(month(GETDATE()) as varchar(6))=202111 and number<=day(GETDATE())) or (cast(year(GETDATE()) as varchar(6)) +cast(month(GETDATE()) as varchar(6))!=202111 and number<=day(dateadd(day,-1, dateadd(MONTH, 1,'2021-11-01')))) )
( SELECT DATEADD(D, number, #QueryDate#) DayNum FROM master..spt_values WHERE type = 'p' <![CDATA[ AND DATEADD(D, number, #QueryDate#) <= (case when (DATEADD(d,-day(#QueryDate#),DATEADD(m,1,#QueryDate#)))>GETDATE() then getdate() else (DATEADD(D,-day(#QueryDate#),DATEADD(M,1,#QueryDate#))) end) ]]> )