0 pts.
 Date Problem
I am trying to create a query in SQL Server that will generate a list of dates starting from Jan 1 2007 and ending Dec 31. I have been able to get them in columns, but I want to get them in rows. Please note that I need the query to dynamically generate the data I want to avoid creating tables. Is this possible using just a query? Please help.

Software/Hardware used:
ASKED: February 3, 2006  3:23 PM
UPDATED: February 6, 2006  3:15 AM

Answer Wiki:
Hello, What about using a user defined function? I mean something like this: CREATE FUNCTION CreateDateList ( @iniDate DATETIME, @endDate DATETIME ) RETURNS @DateList TABLE ( Dates DATETIME ) AS BEGIN DECLARE @workDate DATETIME SET @workDate = @iniDate - 1 WHILE @workDate < @endDate BEGIN SET @workDate = @workDate + 1 INSERT @DateList VALUES (@workDate) END RETURN END Then you could use SELECT * FROM CreateDateList ('01/01/07', '31/12/07') --Likely '12/31/07' for you to get all the rows you need. Judith
Last Wiki Answer Submitted:  February 6, 2006  3:15 am  by  19780625   0 pts.
All Answer Wiki Contributors:  19780625   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _