Q&A

  • 중첩while 문안에 커서돌리기


커서를 선언하고 while문에서

또다른 커서를 선언한다음 이를 while문으로 돌리고 싶은데

다음과 같이 하면 결과가,



첫커서의 첫레코드에 대한 커서만이 생성되어 while문을 돈다음 바로 빠집니다.



(참고) mssql7.0

---------------------------------------------------

declare @io_date smalldatetime

,@io_no numeric

,@ac_kum numeric

,@ac_code varchar

,@ac_cha numeric

,@ac_dae numeric

,@io_date2 smalldatetime

,@io_no2 numeric



declare cursor_test insensitive cursor



for select IO_DATE, IO_NO, ISNULL(SUM(AC_CHA+AC_DAE),0) AC_KUM

from AC_SLIP

where SA_SNO =1

and IO_DATE ='2001-04-13'

AND AC_CODE='01010101010'

GROUP BY IO_DATE, IO_NO



open cursor_test

while (@@cursor_rows<>0) begin

fetch cursor_test into @io_date, @io_no, @ac_kum

if @@fetch_status = -1 break



select @io_date, @io_no, @ac_kum





declare cursor_test2 insensitive cursor

for select IO_DATE, IO_NO, AC_CODE, AC_CHA, AC_DAE

from AC_SLIP

where SA_SNO =1

and IO_DATE =@io_date

and IO_NO=@io_no

and AC_CODE <> '01010101010'



open cursor_test2

while (@@cursor_rows<>0) begin

fetch cursor_test2 into @io_date2, @io_no2, @ac_code, @ac_cha, @ac_dae

if @@fetch_status = -1 break



select @io_date2, @io_no2, @ac_code, @ac_cha, @ac_dae

end

close cursor_test2

deallocate cursor_test2





end



close cursor_test

deallocate cursor_test

----------------------------------























0  COMMENTS