I'm trying to insert into a table that is joined in my c# program, I'm having an issue with the below SQL statement on SQL Server:
INSERT INTO DartBox (DartBoxNumber, ReturnDate, Comments, SerialSDD)
VALUES (1, 2, 3, 4)
SELECT d.DartBoxNumber, d.ReturnDate, d.Comments, s.SerialSDD
FROM DartBox d
LEFT JOIN DartBoxSerials s ON d.DartBoxID = s.DartBoxReturnID
I want to insert data into two tables at once, there is a relationship between DartBox and DartBoxSerials (there can be many serials in the dartbox)
When I try and run the query in SQL I get:
Invalid column name 'SerialSDD'.
It does exist in the joined output though.
Any assistance would be great?
This worked using the link below and this is how to do it: (I've removed the date bit due to a type mismatch)
BEGIN TRANSACTION
DECLARE @DataID int;
INSERT INTO DartBox (DartBoxNumber, Comments)
VALUES (1, 3)
SELECT @DataID = scope_identity();
INSERT INTO DartBoxSerials (DartBoxReturnID, SerialSDD)
VALUES (@DataID, 4);
COMMIT