cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Anywere 12 insert record for each date between two dates

eric_verhorstert
Explorer
0 Kudos
113

A part of a function in our database looks like this:

while @datecount <= today() loop

    set @datecount = dateadd(day, 1, @datecount);


    insert into gt_datetable( countdate ) values ( @datecount );

end loop;

We have to insert about 200000 records in this way and wonder if there is a script with a better performance.

Thanks

Eric

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Not sure I fully understand your question, but the following should be able to generate all the dates you need and insert them in one statement, should be much quicker, if this is indeed what you want

begin
     declare @datecount date;
     declare @datedelta integer;
     set @datecount = dateadd(day, -200000, today());

     set @datedelta = datediff( day, @datecount, today());

     insert into gt_datetable( countdate ) select dateadd(day,row_num,@datecount) from sa_rowgenerator( 1, @datedelta );
end

Answers (0)