Re: itinerating for insert into (rownumber, fetchstatus)




Hi
select * from table where table.field = x and rowid = @k
You meant
select * from [table ordered by rowid] where table.field = x and rowid = @k

insert into .....select row_number() over (order by id asc) as rowid from
tbl --does not help?







"André Freitas" <thevirus@xxxxxxxxxx> wrote in message
news:e1atdaFAKHA.5020@xxxxxxxxxxxxxxxxxxxxxxx
well, i have to insert a set of result in another table, and i choosed the
following aproach:

declare @i int

declare @k int
set @k = 1

select @i = count(id) from table where table.field = (some value)

while @k <= @i
begin

with [table ordered by rowid] as
(select row_number() over (order by id asc) as rowid from table where
field = x)
select * from table where table.field = x and rowid = @k
insert into...

set @k = @k + 1

end


I know i can do the same with fetchstatus (but the cursor thing makes me
think twice). So, anyone can tell me a best aproach, or the above one is a
good idea?

thx, Regards.


.



Relevant Pages


Quantcast