|
I need to add a set of records (dates) to a calander table....I know there is a way to loop through and add a year dynamically but not sure of the syntax... can someone help?
(comments are locked)
|
|
You want to avoid using loops - that's not what SQL was created for. If you can use a set-based approach, you should use it. Your specific question is yet another use for a Tally table: EDIT I've updated my answer, based on the comment made, that the first column should contain consecutive dates, and the second should contain the same value when weekday is Mon-Fri, otherwise the next workday. END EDIT Magnus thank you so much...I am troubleshooting and over the hump of the immediate crisis... I have a two column table that has prc effective date and col 2 = next prc eff date. the next prc eff date considers the weekend so how can I build the day of week logic into the table load that says if the dw = 6,7 then use the next monday day of week?
Dec 30 '10 at 01:46 PM
siera_gld
Add to the query. You might want to add to the beginning of the batch as well, to make sure you get sunday treated as day seven and not day 1.
Dec 30 '10 at 01:58 PM
Magnus Ahlkvist
Or if you mean that you want one column containing all dates (incl. saturdays and sundays) and the other column containing the first workday after the first column, you'd want:
Dec 30 '10 at 02:09 PM
Magnus Ahlkvist
Almost - it displays this I need it to load this Do you see how my next eff dt column skips gthe weekends but my eff date does not? I also need to adjust the weekday to 7,1
Dec 30 '10 at 02:26 PM
siera_gld
That's almost what my last comment does. I was one day wrong in the second column. This should be right. I'll update my answer with the code as well
Dec 30 '10 at 02:37 PM
Magnus Ahlkvist
(comments are locked)
|

