3초기억력

MS-SQL- Cursor 사용 예제2 본문

쿼리_MSSQL

MS-SQL- Cursor 사용 예제2

잠수콩 2010. 4. 6. 14:34

프로시저 및 커서

***설명
  프로시저에 커서 선언해서 사용하는 방법


***코드
alter procedure usp_p_personal_info(@rtnint         output                ) as
        DECLARE        @UPDT_DT DATETIME
        DELETE M_TB_COM_PERSONAL_INFO
        
BEGIN
        DECLARE CUR_2 CURSOR FOR
                SELECTeif_seq_no AS individual_no
                FROM        airtest.dbo.atst_200(nolock)
                WHERE        and eif_seq_no = '1000063830'
                ORDER BY eif_seq_no ASC

        OPEN CUR_2
        
        SELECT@UPDT_DT                        = NULL
        
        FETCH NEXT FROM CUR_2
        INTO         @individual_no
        
        WHILE @@FETCH_STATUS=0
        BEGIN
                ----[ 소속코드 신코드 변환 ]------------------------------------------------
                SELECT        @place_cd = dbo.ufn_t_place_cd(b.cdi_ps_gb, b.cdi_ps_cd)
                FROM        airtest.dbo.atst_200 a , airtest.dbo.atst_106 b
                WHERE        a.cdi_sw_seq_no = b.cdi_sw_seq_no
                        AND a.eif_seq_no = @individual_no
        
                INSERTM_TB_COM_PERSONAL_INFO
                        SELECT@individual_no
        
                SELECT        @individual_no = NULL

                FETCH NEXT FROM CUR_2
                INTO @individual_no
        END
        
        CLOSE CUR_2
        DEALLOCATE CUR_2
END
Comments