all groups > sql server (alternate) > november 2003 >
You're in the

sql server (alternate)

group:

Sql Stored Procedures


Re: Sql Stored Procedures oj
11/29/2003 11:21:12 AM
sql server (alternate):
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



[quoted text, click to view]

Sql Stored Procedures Jarrod Morrison
11/29/2003 8:39:28 PM
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

AddThis Social Bookmark Button