I have 2 tables - tblOrders and tblOrderDetails . Every time an order is placed, 2 INSERT statements are executed. The first one enters the general order and customer information in the tblOrders table:
The primary key in this table is OrderID which is an Identity column. This is the foreign key in the tblOrderDetails table.
I'm trying to get the Identity value from the first INSERT statement to use in the second INSERT statement:
How do i obtain this value and how would I supply it to the second INSERT statement.
Code:
INSERT INTO tblOrders (custname, custdetails, orderdate) VALUES (@custname, @custdetails, @orderdate)
I'm trying to get the Identity value from the first INSERT statement to use in the second INSERT statement:
Code:
INSERT INTO tblOrderDetails (orderid, productid, productcost) VALUES (@orderid, @productid, @productcost)
Comment