开发者

How to insert saturdays and sundays between two dates in a table using sql?

开发者 https://www.devze.com 2023-02-25 11:41 出处:网络
Say starting date is 8/04开发者_运维技巧/2010 ending date is 8/04/2011 I need the dates of saturdays and sundays to be inserted in a table...

Say starting date is 8/04开发者_运维技巧/2010 ending date is 8/04/2011 I need the dates of saturdays and sundays to be inserted in a table... Need Help


Use an unambiguous date format, like '2010-08-04'. This sorts correctly as either date or text, and everybody knows it means 04-Aug, not 08-Apr.

I like to use a calendar table for queries like this. This will select the dates.

select cal_date
from calendar
where cal_date between '2010-08-04' and '2011-08-04'
and (day_of_week = 'Sat' or day_of_week = 'Sun');

Something like this will insert them into a table. (Depending on the table.)

insert into your_table_name
select cal_date
from calendar
where cal_date between '2010-08-04' and '2011-08-04'
and (day_of_week = 'Sat' or day_of_week = 'Sun');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号