본문 바로가기
MS-SQL/Query

CURSOR 간단한 예제.

by Hwoarang757 2013. 3. 8.

 

 

DECLARE @CUR_ACTION_ORDER INT

DECLARE @CUR_PDSSSCHE_GROUPCODE INT

 

DECLARE CURSOR_ORDER CURSOR FOR

 

SELECT ACTION_ORDER,PDSSCHE_GROUPCODE FROM  ASPECT_FEED.DBO.PDSSCHE_ACTION_TBL 

WHERE PDSSCHE_SERVICEID = @SERVICEID AND ACTION_ORDER IS NOT NULL

 

OPEN CURSOR_ORDER

 

FETCH NEXT FROM CURSOR_ORDER  INTO @CUR_ACTION_ORDER,@CUR_PDSSSCHE_GROUPCODE

 

WHILE @@FETCH_STATUS = 0

BEGIN

                                                                                                                                                                                                                   

 

IF ISNULL(@ACTION_ORDER_NUM,0) < @CUR_ACTION_ORDER

BEGIN

             

                                                                                                                                                                                                                                                            

 

PRINT '@CUR_ACTION_ORDER 값이더큽니다.'

 

                                                                                                                                                                                

FETCH NEXT FROM CURSOR_ORDER INTO @CUR_ACTION_ORDER,@CUR_PDSSSCHE_GROUPCODE

END

 

 

CLOSE CURSOR_ORDER

DEALLOCATE CURSOR_ORDER

 

--설명이 없어 죄송합니다 ;;;