Last post May 09, 2019 02:37 AM by Wei Zhang
May 08, 2019 01:26 PM|akhterr|LINK
i have table
Now i want store procedure to insert record into a table of sql on one button click ,orderID from salesorder table auto insert into orderID of orderDetail table
please guide thanks
May 09, 2019 02:37 AM|Wei Zhang|LINK
According to your description,you could use SCOPE_IDENTITY() to get column value which identity(1,1) in the database table. You could firstly int CustomerName and Data value in SalesOrder, then you could use SCOPE_IDENTITY() to get OrderID value, then
you could insert value in OrderDetail then you could get ID which is also identity growth in table OrderDetail. Here is a demo, I hope it could help you.
CREATE PROCEDURE PRO
CREATE TABLE SalesOrder(OrderID INT IDENTITY(1,1), CustomerName CHAR(1));
INSERT SalesOrder(CustomerName) VALUES('C');
declare @a int;
CREATE TABLE OrderDetail(ID INT IDENTITY(1,1), OrderID CHAR(1));
INSERT OrderDetail(OrderID) values(@a)
Here is the link for SCOPE_IDENTITY() , I hope it could help you.