Link to home
Start Free TrialLog in
Avatar of Terrace
TerraceFlag for United States of America

asked on

SQL 2000 - for Loop to insert a range of dates and values at once

What is the best way to do this?

Have a table tblMax  with DateFund and Maxvalue fields.

Need to fill that table with range of dates from 02/12/2009 - 01/01/2010

DateFund        MaxValue
02/12/2009     0
02/13/2009     0
etc

I guess it would be some For Loop in SQL Analizer or Stored Procedure.

Can anyone write me a quick simple code for it?

Thanks
Avatar of tigin44
tigin44
Flag of Türkiye image

declare @tmp datetime

set @tmp = '02/12/2009'

while @tmp <= '01/01/2010'
begin
   insert into yourTable(DateFund, MaxValue)
   values  (@tmp, 0)
   
   set @tmp = dateadd(day, @tmp, 1)
end

ASKER CERTIFIED SOLUTION
Avatar of tigin44
tigin44
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial