Problem : T-SQL Do while not EOF

Problem : T-SQL Do while not EOF

Hi,

I want to know is there any command in T-SQL have the same function like VB5;

Do until resultset.EOF
…….
resultset.movenext
Loop

I have declare a cursor for a select statement, and fetch the cursor into some variable for further processing in other stored proc.

The statement look like :-
————————————————-
declare hk_cursor scroll cursor for
select stud_id, stud_name from tblStudent

OPEN hk_cursor
fetch first from hk_cursor into @var1,@var2
EXEC sp_my_stored_proc @var1,@var2

while (@@fetch_status=0)
BEGIN
EXEC sp_my_stored_proc @var1,@var2
FETCH NEXT hk_cursor into @var1,@var2
END

close hk_cursor
deallocate hk_cursor

————————————————-

Actually, I want to loop thru the results selected by the cursor and pass it into my stored procedure for furhter processing…

Thanks.


Solution: T-SQL Do while not EOF

oops.. missed out some lines.. try the following

—————————-
declare @var1 int
declare @var2 varchar(50)

declare hk_cursor cursor for
select stud_id, stud_name from tblStudent

OPEN hk_cursor
fetch next from hk_cursor into @var1,@var2
while (@@fetch_status=0)
BEGIN
EXEC sp_my_stored_proc @var1,@var2
FETCH NEXT from hk_cursor into @var1,@var2
END

close hk_cursor
deallocate hk_cursor