저장 프로시저를 만들고 있는 초보자입니다.
create proc TEST
(
@reqdt char(8),
@orgCode char(10),
@cheak char(1)
)
As
Case
when cheak = '0' then update ea13mst set status = 1 where reqdt = @reqdt and orgcode = @orgcode
when cheak = '1' then update ea21mst set status = 1 where reqdt = @reqdt and orgcode = @orgcode
End Case
cheak 값이 0 일 때는 update ea13mst set status = 1 where reqdt = @reqdt and orgcode = @orgcode 처리 하고 싶고
1 일 때에는 update ea21mst set status = 1 where reqdt = @reqdt and orgcode = @orgcode 처리 할려고 하는데
어떻게 쿼리를 만들어야하나요..?
Comment 4
-
이리
2017.11.13 16:43
-
JoWonGi
2017.11.13 17:05
Create proc TEST
(
@reqdt char(8)
@orgCode char(10)
@cheak char(1)
)
As
Begin
IF cheak = '1' then update ea13mst set status = '1' where reqdt = @reqdt and orgcode = @orgcode
elseif cheak = '2' then update ea21mst set status = '1' where reqdt = @reqdt and orgcode = @orgcode
ENDIF
END
이렇게 했었는데 어디가 잘못 되었는지 모르겠네요..
-
이리
2017.11.13 17:11
https://technet.microsoft.com/ko-kr/library/ms187471(v=sql.105).aspx
문법 관련해서는 MSDN을 참고 하시면 됩니다.
Create proc TEST
(
@reqdt char(8)
,@orgCode char(10)
,@cheak char(1)
)
As
Begin
IF @cheak = '1'
BEGIN
update ea13mst set status = '1' where reqdt = @reqdt and orgcode = @orgcode
END
else IF @cheak = '2'
BEGIN
update ea21mst set status = '1' where reqdt = @reqdt and orgcode = @orgcode
END
END
-
JoWonGi
2017.11.13 22:19
정말정말 감사합니다!!
IF 문으로 하시면 됩니다.