获取每月天数以及星期几
WITH a AS(
SELECT
DATEADD(DAY, NUMBER, CONVERT(DATE, '2024-02-01')) AS "24年2月份天数"
FROM MASTER..SPT_VALUES
WHERE TYPE='P'
AND NUMBER BETWEEN 0 AND DATEDIFF(DAY, '2024-02-01', DATEADD(MONTH, 1, '2024-02-01'))-1
),
b AS(
SELECT *,
CASE DATEPART(weekday,"24年2月份天数")
WHEN 1 THEN '星期天'
WHEN 2 THEN '星期一'
WHEN 3 THEN '星期二'
WHEN 4 THEN '星期三'
WHEN 5 THEN '星期四'
WHEN 6 THEN '星期五'
WHEN 7 THEN '星期六'
END AS '星期几' FROM a
)
SELECT * FROM b