Thursday, October 11, 2012

get back the auto-incrementing id from a sproc

USE [IT]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_tblUsers_Insert]
   @UserID int = null OUTPUT,
   @FirstName varchar(50),
   @LastName varchar(50)
AS
BEGIN
INSERT INTO tblUsers (FirstName, LastName) VALUES (@FirstName, @LastName)
SELECT @UserID = IDENT_CURRENT('tblUsers')
END
GO

No comments:

Post a Comment