I have 2 tables, the first table contains the minor details on the item and the second table contains the rest of the information.
BEGIN TRANSACTION;
INSERT INTO Items (Name, CategoryId)
VALUES ('My Tv', 5);
INSERT INTO CharsToItem (ItemId, Value)
VALUES ((SELECT Id FROM Items WHERE Id = @@Identity;), '65 Inch');
INSERT INTO CharsToItem (ItemId, Value)
VALUES ((SELECT Id FROM Items WHERE Id = @@Identity;), '3840x2160');
COMMIT;
At the first insert to the CharToItem
table, everything works perfectly, at the second time it says the return value is NULL and I can't insert it to the database.
Is there a way to save the Id in the select and use it several times?