on 2014 Sep 25 3:06 PM
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
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
11 | |
9 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.