Nested Cursor Code

Sabarimahesh
Posted by Sabarimahesh under Sql Server category on | Points: 40 | Views : 2443
Simple Code For NestCode......................................


declare @id int
declare @name varchar(5000)
DECLARE CURSOR_one CURSOR FOR select id from table1
OPEN CURSOR_one
FETCH NEXT FROM CURSOR_one INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN

DECLARE CURSOR_Two cursor for select addres from table2 where id=@id
OPEN CURSOR_Two
FETCH NEXT FROM CURSOR_Two INTO @name
WHILE @@FETCH_STATUS=0
BEGIN
print @name
FETCH NEXT FROM CURSOR_Two INTO @name
END
CLOSE CURSOR_Two
DEALLOCATE CURSOR_Two
FETCH NEXT FROM CURSOR_one INTO @id
END
CLOSE CURSOR_one
DEALLOCATE CURSOR_one

Comments or Responses

Login to post response