December 6, 2009 at 11:12 pm
I'm trying to populate my db.
Here first the cursor populates with say 10 rows and I want for each row I get I should have 1500 row in someother table.
My query here catches only first row from cursor and populates 1500 row in other table.. And it does not take the 2 data from cursor What is that I'm missing here
(This is only one time activity.. So cursor is ok)
declare @resnr int ,@res_seqnr int, @tot int set @resnr=1144894 set @tot = @resnr + 1500 print @tot
declare results_cur cursor for
select sequencenr from sequenctbl where Inst = 8323
open results_cur
fetch next from results_cur into @res_seqnr
while @@fetch_status = 0
BEGIN
While (@resnr <= @tot)
begin
INSERT INTO [my_tbl]
([SequenceNr],[TimeInfo],[Conc],[Excluded],[ResultNr]
,[SampleRunNr)
VALUES (@res_seqnr, getdate(),100.000000,0,@resnr,@resnr)
print 'in inner while'
set @resnr= @resnr +1
end
fetch next from results_cur into @res_seqnr end
END
CLOSE results_cur
DEALLOCATE results_cur
December 7, 2009 at 3:28 am
You should reinitialize (between BEGIN and second WHILE)
either @resnr or @tot, like you did in the beginning:
set @resnr=1144894
set @tot = @resnr + 1500
or when you want to count further only
set @tot = @resnr + 1500
will do.
HTH
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply