if(exists (select * from dbo.Rs_ry where Rbh=@Rbh))
BEGIN
UPDATE dbo.Rs_ry
SET Sbh=@Sbh,Xm=@Xm,Mm=@Mm,LZ=@Lz,Zzbh=@Zzbh,Sssbh=@Sssbh
where Rbh = @Rbh
if @@ERROR <> 0 goto errorEnd
END
ELSE
BEGIN
INSERT INTO dbo.Rs_ry
VALUES (@Rbh,@Sbh,@Xm,@Mm,@Lz,@Zzbh,@Sssbh)
select * from dbo.Rs_ry where Rbh = @Rbh
if @@ERROR <> 0 goto errorEnd
END
if @@trancount > 0 commit transaction
errorEnd:
if @@error >0 rollback transaction ------解决方案-------------------- 你把它写好了,就看出来了:
if(exists (select * from dbo.Rs_ry where Rbh=@Rbh))
BEGIN
UPDATE dbo.Rs_ry
SET Sbh=@Sbh,Xm=@Xm,Mm=@Mm,LZ=@Lz,Zzbh=@Zzbh,Sssbh=@Sssbh
where Rbh = @Rbh
if @@ERROR <> 0 goto errorEnd
END
ELSE
BEGIN
INSERT INTO dbo.Rs_ry
VALUES (@Rbh,@Sbh,@Xm,@Mm,@Lz,@Zzbh,@Sssbh)
select * from dbo.Rs_ry where Rbh = @Rbh
if @@ERROR <> 0 goto errorEnd
END