SQL and multiple statements in stored procedure
Posted
by Sjemmie
on Stack Overflow
See other posts from Stack Overflow
or by Sjemmie
Published on 2010-03-12T12:21:58Z
Indexed on
2010/03/12
12:27 UTC
Read the original article
Hit count: 124
sql
I'm working on SQL server 2005 and I have a very simple stored procedure:
create PROCEDURE [dbo].[tblTabel_Insert]
@ID int,
@Code nvarchar(50) = null
AS
SET NOCOUNT ON;
IF EXISTS (SELECT ID, code FROM tblTabel WHERE ID = @ID and code = @Code)
UPDATE tblTabel SET ID = @ID,code = @Code WHERE ID = @ID
ELSE
BEGIN
INSERT INTO tblTabel (ID,code) VALUES ( @ID ,@Code);
END
My question is: is it posible to have multiple queries in my stored procedure ? I want to add the lines
UPDATE tblTabelB SET ID = @ID,code = @Code WHERE ID = @ID
UPDATE tblTabelC SET ID = @ID,code = @Code WHERE ID = @ID
in my if exists section. How do I change my stored procedure in the correct way ?
© Stack Overflow or respective owner