Hi, I am trying to have a procedure that it checks if some data exist on one table and if it does then it perfoms an update in another table and if it doesn't then does nothing. I have the following procedure, although it doesn't actually work yet don't know why
, this shows my idea. Is this the right way of doign this?
CREATE procedure ChangeStatus
(
@pID int,
@cID int,
@lID int,
@sNME varchar(50) OUTPUT,
@sADD varchar(100) OUTPUT
)
as
select
@sNME=sNME,
@sADD=sADD
from
table1
where
(pID = @pID)
begin
set XACT_ABORT ON
DECLARE @EXIST int
begin transaction
set nocount on
set @EXIST = (select b_sNME FROM table2 WHERE (UPPER(b_sNME) = @sNME) AND (b_cID= @cID))
if (@EXIST) begin
update
table3
set
fStatus=2
where
uID=@lID
end
commit transaction
end
GO
CREATE procedure ChangeStatus
(
@pID int,
@cID int,
@lID int,
@sNME varchar(50) OUTPUT,
@sADD varchar(100) OUTPUT
)
as
select
@sNME=sNME,
@sADD=sADD
from
table1
where
(pID = @pID)
begin
set XACT_ABORT ON
DECLARE @EXIST int
begin transaction
set nocount on
set @EXIST = (select b_sNME FROM table2 WHERE (UPPER(b_sNME) = @sNME) AND (b_cID= @cID))
if (@EXIST) begin
update
table3
set
fStatus=2
where
uID=@lID
end
commit transaction
end
GO