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?
views:
44answers:
1
+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
keith
2010-10-26 09:53:59
And it is slow. Avoid cursors as much as you can - which means rewrite the sp ;)
TomTom
2010-10-26 09:57:00
Speed is not a concern. The procedure will be executed nightly when the systems is offline.
Luca Martini
2010-10-26 10:01:56
@keith I would like to avoid declaring so many variables, because the table has more than 40 fields...
Luca Martini
2010-10-26 10:59:56