Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-05-26 : 08:14:39
|
| ashish writes "I need to insert date in a column which should start from 1st jan 2005 and keep on inserting date till today. How should I achieve that.I tried :- But it is inserting same date. Whats wrong with dateadd function.===============================================================Declare @today DatetimeDeclare @todaydate datetimeset @today = '2005-01-01'WHILE (SELECT Today=GETDATE()) > '2005-01-01'BEGIN Insert tablename(date_insert) Values (@todaydate) select @todaydate = dateadd(day,1,@today) print @todaydate IF (SELECT Today=GETDATE()) < '2005-05-25' BREAK ELSE CONTINUEEND" |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-05-26 : 08:24:02
|
I think you tried to make this waaaaaaay too complicated.DECLARE @table TABLE(datecol DATETIME)DECLARE @today DATETIMESET @today = '2005-01-01'WHILE @today <= GETDATE()BEGININSERT @table(datecol)VALUES (@today)SELECT @today = DATEADD(day,1,@today)PRINT @todayENDSELECT datecol FROM @table MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|