Hello,I have problem inserting records through my stored procedure.This is the procedure:CREATE PROCEDURE InsertProducts @ProductKey VARCHAR(25), @ProductName VARCHAR(25), @ProductDescription VARCHAR(125), @ProductPrice INT, @ProductQtyOnStock INTAS DECLARE @ProductID SMALLINT -- Insert Values into Products BEGIN TRANSACTION INSERT INTO dbo.Products (ProductKey, Productname, ProductDescription, ProductPrice, ProductQtyOnStock) VALUES (@ProductKey, @ProductName, @ProductDescription, @ProductPrice, @ProductQtyOnStock) COMMIT -- Insert message into ProcedureLog INSERT INTO dbo.ProcedureLog (ProcMessage) VALUES ('ProductKey: ' + @ProductKey + ' with ProductID: ' + CONVERT(VARCHAR(25), @ProductID) + ' inserted successfully!')This is the ProcedureLog-table:-- Created the table ProcedureLogCREATE TABLE ProcedureLog (ProcID SMALLINT IDENTITY(1,1) NOT NULL, ProcMessage VARCHAR(250) NOT NULL PRIMARY KEY (ProcID))
When I run the SP I receive this error:(1 row(s) affected)Msg 515, Level 16, State 2, Procedure InsertProducts, Line 20Cannot insert the value NULL into column 'ProcMessage', table 'master.dbo.ProcedureLog'; column does not allow nulls. INSERT fails.The statement has been terminated.(1 row(s) affected)
If I change (in the SP) to this, it works (I choose a static value instead of a variable):INSERT INTO dbo.ProcedureLog (ProcMessage) VALUES ('ProductKey: ' + @ProductKey + ' with ProductID: ' + CONVERT(VARCHAR(25), 250) + ' inserted successfully!')How do I insert my ProductID? ProductID should be created at the beginning, when I insert the variables into "dbo.Products", of the code but do I need to retrive it somehow perhaps?What is the most easiest and efficient way to proceed?Thanks in advance!Best Regards.KF