griswald65
asked on
Creating a cursor to select in a particular order
I need to cursor a table in a particular order because i am creating a new sort number that is to update the table. Any ideas on how to do this. The cursor is not liking the order by in the select statement for the cursor. Here is what I have:
Declare curNum cursor
For (Select Number, subNumber From ##Table order by sortorder)
Declare @Num varchar (25)
Declare @subnum varchar (25)
Open curNum
Fetch Next from curNum Into @Num, @subnum
While (@@Fetch_Status = 0)
Begin
Then Statement
Fetch Next from curNum into @Num, @subnum
End
Close curNum
Deallocate curNum
Declare curNum cursor
For (Select Number, subNumber From ##Table order by sortorder)
Declare @Num varchar (25)
Declare @subnum varchar (25)
Open curNum
Fetch Next from curNum Into @Num, @subnum
While (@@Fetch_Status = 0)
Begin
Then Statement
Fetch Next from curNum into @Num, @subnum
End
Close curNum
Deallocate curNum
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select * into ##Table2 from ##Table order by sortorder
and then reference ##Table2 instead of ##Table