I am inserting some values into a table using the INSERT
command then I am getting it's inserted value as OUTPUT
. Now I want to select the inserted row by its id using the SELECT
command I am using the following code but it doesn't seem to work.
CREATE PROCEDURE [dbo].[SP_UserRegistration]
(
@Name VARCHAR(100),
@Contact VARCHAR(20),
@DOB VARCHAR(20),
@MailAddress VARCHAR(500),
)
AS
BEGIN
BEGIN TRY
DECLARE @id INT
INSERT INTO Customer (Name, Contact, DOB, MailAddress)
OUTPUT inserted.ID INTO @id
VALUES (@Name, @Contact, @DOB, @MailAddress)
SELECT *
FROM Customer
WHERE ID = @id
END TRY
BEGIN CATCH
PRINT('Error in SP_UserRegistration')
END CATCH
END