I have a script I'm writing in SQL Server 2005, and need a little help with a specific part.
I don't need to get into the details of the script, but at a very high level:
At the very top I declare and set a start and end date, like so:
Then I just call the start and end variables from within the script and do stuff, that's not my question though.Code:DECLARE @start datetime DECLARE @end datetime SET @start = '01/14/2008 00:00:00 AM' SET @end = '01/14/2008 11:59:59 PM'
What I need help with is creating a loop or something that can loop through the dates. Let's say we have a table or array of 90 dates and an 'autonumber' type field that's incremented sequentially at each date, like so:
1 12/01/2007 12/02/2007
2 12/02/2007 12/03/2007
3 12/03/2007 12/04/2007
etc
Then we just need a statement to loop through the days. I'm not a developer, but simplistically, something that basically starts at autonumber 1, grabs the first date and stamps it as the StartDate in the script, grabs the second date and stamps it as the EndDate, then runs the script, then increments the autonumber by one and starts again, until it reaches the end of the table.
Can that be done in SQL, or do we need to use VB to do that and call the script?
Thanks

Reply With Quote


