Stored Procedures That Return the IDENTITY August 21 2006
The secret lies in the function “SCOPE_IDENTITY()” which references that last ID inserted within the scope of the procedure. See the following:
CREATE PROCEDURE [dbo].[usp_FORMS_E_InfoEntry_INSERT]
@NAME VARCHAR(255) ,
@ID_FORMS_E_InfoEntryCategory INT
AS
SET NOCOUNT ON
INSERT INTO [dbo].[FORMS_E_InfoEntry]
(
NAME,
ID_FORMS_E_InfoEntryCategory,
creation_datetime
)
VALUES
(
@NAME,
@ID_FORMS_E_InfoEntryCategory,
GetDate()
)
SELECT SCOPE_IDENTITY() AS ID
SET NOCOUNT OFF
GO
- Posted in : General
- Author : site admin

Comments»
no comments yet - be the first?