且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sql中的特定日期选择给定日期的下一个日期

更新时间:2023-01-28 15:10:25

你可以使用公用表表达式 [ ^ ]:

You can acieve that using Common Table Expressions[^]:
Create procedure Select_Disurbment_Dates
       @inputDate DATETIME   
AS
BEGIN
    --SET DATEFORMAT ymd;

    ;WITH Next3Days AS
    (
	SELECT @inputDate AS MyDate, 0 AS Counter
	UNION ALL
	SELECT DATEADD(dd,1,MyDate), Counter+1 AS Counter
	FROM Next3Days
	WHERE COunter<3
    )
    SELECT CONVERT(VARCHAR(10),MyDate,121) AS MyDate, Counter
    FROM Next3Days
    WHERE Counter>0
END





结果:



Result:

2013-08-22	1
2013-08-23	2
2013-08-24	3





或使用同时 [ ^ ]循环和临时表;)



Or use while[^] loop and temporary table ;)


这对你也很有用



http://***.com/questions/ 12638256 / how-to-select-last-three-month-all-date-in-sql-server [ ^ ]



http://***.com/questions/5196822/select-最近3个月的最大和最小日期 [ ^ ]



HTTP:// drupal的.stackexchange.com / questions / 35200 / how-do-i-query-for-next-three-dates-using-entityfieldquery-or-views-7 [ ^ ]

问候..:)
this may also useful to you

http://***.com/questions/12638256/how-to-select-last-three-month-all-dates-in-sql-server[^]

http://***.com/questions/5196822/select-the-maximal-and-minimum-dates-in-the-last-3-months[^]

http://drupal.stackexchange.com/questions/35200/how-do-i-query-for-the-next-three-dates-using-entityfieldquery-or-views-7[^]
regards ..:)