views:

44

answers:

1

I'm about to convert a stored procedure from pl/sql to SQL Server. The procedure uses a cursor to loop through the results of a select query. Is there a SQL Server equivalent to the ORACLE rowtype construct?

+1  A: 

The SQL way of using a cursor is shown below

DECLARE @colA varchar(50), @colB varchar(50)

DECLARE myCursor CURSOR FOR
Select columnA, columnB From table

OPEN myCursor

FETCH NEXT FROM myCursor INTO @colA, @colB

WHILE @@FETCH_STATUS = 0
BEGIN

--do something with @colA and @colB

FETCH NEXT FROM myCursor INTO @colA, @colB

END

CLOSE myCursor
DEALLOCATE myCursor

reference link

keith
And it is slow. Avoid cursors as much as you can - which means rewrite the sp ;)
TomTom
Speed is not a concern. The procedure will be executed nightly when the systems is offline.
Luca Martini
@keith I would like to avoid declaring so many variables, because the table has more than 40 fields...
Luca Martini