某年(返回2024整年天数列表)
SELECT CONVERT
( VARCHAR ( 10 ), dateadd( DAY, t2.number, t1.day ), 120 ) DAY
FROM
( SELECT '2024-01' + '-01' DAY ) t1,
( SELECT number FROM MASTER..spt_values WHERE TYPE = 'P' AND number >= 0 AND number <= 366 ) t2
WHERE
CONVERT ( VARCHAR ( 10 ), dateadd( DAY, t2.number, t1.day ), 120 ) LIKE '2024%'
某月(返回2月整月天数列表)
SELECT CONVERT
( VARCHAR ( 10 ), dateadd( DAY, t2.number, t1.day ), 120 ) DAY
FROM
( SELECT '2024-02' + '-02' 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 '2024-02%'