DECLARE @FLOCCDE VARCHAR ( 50 ) ; -- 대체창고코드
DECLARE @FITMCDE VARCHAR ( 50 ) ; -- 대체대상자재코드
DECLARE @FQTY FLOAT ; -- 대체대상자재수량
DECLARE @FCHAITM VARCHAR ( 50 ) ; -- 대체자재코드
DECLARE @FCHAQTY FLOAT ; -- 대체수량
-- HSH 2006.10.24 추가
-- 자재변경
DECLARE UP_MB1601_CHA_CUR CURSOR FOR
SELECT FLOCCDE, FITMCDE, FQTY,FCHAITM,FCHAQTY
FROM XPERTERP.T_C144
WHERE FLOCCDE = 'S-0033' AND FCHADAT = @FYEARMONTH || @FSTOCKDAY;
FOR FETCH ONLY ;
SET AT_END = 0 ;
OPEN UP_MB1601_CHA_CUR ;
FETCH UP_MB1601_CHA_CUR INTO @FITMCDE, @FQTY,@FCHAITM, @FCHAQTY ;
WHILE AT_END = 0 DO
-- 대체대상자재코드
IF EXISTS ( SELECT * FROM XPERTERP . T_M162 WHERE FMATYXM = @FYEARMONTH AND FMATDAT = @FSTOCKDAY AND FMATCDE = @FITMCDE AND FSTGDPT = '0008888' ) THEN
UPDATE XPERTERP . T_M162 SET FOUTQTY = FOUTQTY + @FQTY
WHERE FMATYXM = @FYEARMONTH AND FMATDAT = @FSTOCKDAY AND FMATCDE = @FITMCDE AND FSTGDPT = '0008888' ;
ELSE
INSERT INTO XPERTERP . T_M162 ( FMATYXM , FMATDAT , FMATCDE , FMATDIV , FOUTQTY , FSTGDPT )
VALUES ( @FYEARMONTH , @FSTOCKDAY , @FITMCDE , 'A' , @FQTY , '0008888' ) ;
END IF ;
-- 대체자재코드
IF EXISTS ( SELECT * FROM XPERTERP . T_M162 WHERE FMATYXM = @FYEARMONTH AND FMATDAT = @FSTOCKDAY AND FMATCDE = @FCHAITM AND FSTGDPT = '0008888' ) THEN
UPDATE XPERTERP . T_M162 SET FINPQTY = FINPQTY + @FCHAQTY
WHERE FMATYXM = @FYEARMONTH AND FMATDAT = @FSTOCKDAY AND FMATCDE = @FCHAITM AND FSTGDPT = '0008888' ;
ELSE
INSERT INTO XPERTERP . T_M162 ( FMATYXM , FMATDAT , FMATCDE , FMATDIV , FINPQTY , FSTGDPT )
VALUES ( @FYEARMONTH , @FSTOCKDAY , @FCHAITM , 'A' , @FCHAQTY , '0008888' ) ;
END IF ;
FETCH UP_MB1601_CHA_CUR INTO @FITMCDE, @FQTY,@FCHAITM, @FCHAQTY ;
END WHILE ;
CLOSE UP_MB1601_CHA_CUR ;
위 문장을 실행하면 "SQL문이 너무 길거나 복잡합니다"라는 메시지가 뜨면서 저장 프로시져가
만들어 지지 않습니다. 고수님들의 조언 부탁 드립니다.
|