gpt4 book ai didi

sql - 两个日期之间的月份

转载 作者:行者123 更新时间:2023-12-02 00:32:56 25 4
gpt4 key购买 nike

是否可以获取SQl中两个日期之间的月份名称

即, 2011-05-012011-08-01 是输入我只想输出为

------------
Month
------------
May
June
July
August

如果有人知道该查询,请分享。

最佳答案

DECLARE @StartDate  DATETIME,
@EndDate DATETIME;

SELECT @StartDate = '20110501'
,@EndDate = '20110801';


SELECT DATENAME(MONTH, DATEADD(MONTH, x.number, @StartDate)) AS MonthName
FROM master.dbo.spt_values x
WHERE x.type = 'P'
AND x.number <= DATEDIFF(MONTH, @StartDate, @EndDate);

结果:

MonthName
------------------------------
May
June
July
August

(4 row(s) affected)

关于sql - 两个日期之间的月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7885851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com