Yes, you can. However, it's best to use set based in sql.
Here is an example of row-by-row processing (not recommended in sql).
e.g.
create procedure _usp
as
set nocount on
declare cc cursor fast_forward
for select OrderID
from Northwind..Orders
declare @o int
open cc
fetch next from cc into @o
while @@fetch_status=0
begin
print('OrderID: '+cast(@o as varchar))
fetch next from cc into @o
end
close cc
deallocate cc
go
--exec the sproc
exec _usp
go
--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net
"Jarrod Morrison" <ja*****@ihug.com.au> wrote in message
news:bq**********@lust.ihug.co.nz...
Hi All
I was wondering if there was a way inside a sql stored procedure to step
through the rows of a table using a loop so i can take a value from each
row one by one until i reach the end of the table ? I am used to doing this in
vb by referencing the row numbers one by one in a loop but am unsure if i
can do this in a stored procedure.
Many thanks