Get insert Id from stored proc sql using OUTPUT

ALTER PROCEDURE sp_Mydemo
— Add the parameters for the stored procedure here

@Name nvarchar (520),
@Date nvarchar (520),

AS
BEGIN

insert into data.MyTable
(Name,Date)
OUTPUT INSERTED.Id
values
(@Name,@Date)

END
GO

call sp –

DECLARE @Name nvarchar (520) = ‘test’;
DECLARE @Date nvarchar (520)= ‘2018-03-22 14:57:41.687’;

exec sp_Mydemo @Name , @Date

it will return new GUID inserted bcoz its identity auto generated 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s