Skip to content
Advertisement

sql while loop with date counter

I need to do something like this in sql:

How can I do the above correctly in SQL? Basically, my startdate and enddate are strings and not datetimes because my business logic is referencing string column in another table with a date as the name of the column-But I need to loop through a bunch of columns, each column having the name of the next day’s date.

If the date is 11/07/2009, the name of the column would be ’11/7/2009′ (without the 0 in the 7), so I have to watch out for that too.

Any help is appreciated!

Thanks.

Advertisement

Answer

You can convert the date params to datetime.

then you can use date functions to add days.

As a solution to get a m/d/yyyy format, I C&P this function from some website a couple of weeks ago. Use this code to create a function and call in this way:


User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement