yshie
April 7th, 2007, 09:35 AM
is it possible to create multiple sql commands in one stored procedure?
in my button click, i have to insert values in two tables so it is one way i thought of but i don't know if its correct.
CREATE PROCEDURE dbo.SP1
(
@OrderDate DATETIME,
@OrderID INT,
@ProdID INT
)
AS
/* SET NOCOUNT ON */
INSERT INTO Orders
VALUES(@OrderDate) //this is the insert command for my first table i don't insert orderID(PK) here because it is autonumber
SELECT @OrderID=OrderID
FROM Orders //i don't know if this command is correct but what i want to do is get the orderID based on the above statement
INSERT INTO OrderDetails
VALUES(@OrderID, @MenuID) //this is the insert command for the second table
RETURN
this stored procedure is working good for the first table but not when i added insert on the second table. maybe because of my Select statement
in my button click, i have to insert values in two tables so it is one way i thought of but i don't know if its correct.
CREATE PROCEDURE dbo.SP1
(
@OrderDate DATETIME,
@OrderID INT,
@ProdID INT
)
AS
/* SET NOCOUNT ON */
INSERT INTO Orders
VALUES(@OrderDate) //this is the insert command for my first table i don't insert orderID(PK) here because it is autonumber
SELECT @OrderID=OrderID
FROM Orders //i don't know if this command is correct but what i want to do is get the orderID based on the above statement
INSERT INTO OrderDetails
VALUES(@OrderID, @MenuID) //this is the insert command for the second table
RETURN
this stored procedure is working good for the first table but not when i added insert on the second table. maybe because of my Select statement