I have a stored procedure that is meant to update two tables at once.
My problem here is that the first table has an auto-incrementing ID column ("commentID") and my second table has a relationship on this so I need the newly created ID from the first INSERT in order to make the second INSERT.
I tried the following which I can save without errors but it doesnt execute as it should and does not update the tables as intended. Can someone tell me what I am doing wrong here ?
My SQL:
ALTER PROCEDURE [dbo].[MOC_UpdateComment] @imgID int, @commentID int = '999999', @comment nvarchar(1000), @lastUpdate nvarchar(50), @modBy varchar(50) AS BEGIN DECLARE @temp AS TABLE ( commentID int ) SET NOCOUNT ON; BEGIN TRANSACTION; INSERT INTO MOC_BlogComments ( imgID, comment ) OUTPUT inserted.commentID INTO @temp(commentID) SELECT @imgID, @comment INSERT INTO MOC_LogComments ( commentID, lastUpdate, modTime, modBy ) SELECT commentID, @lastUpdate, GETDATE(), @modBy FROM @temp COMMIT TRANSACTION; END