How to make a stored procedure return the last inserted id

Posted by Luke101 on Stack Overflow See other posts from Stack Overflow or by Luke101
Published on 2010-04-26T02:52:32Z Indexed on 2010/04/26 3:03 UTC
Read the original article Hit count: 293

Filed under:
|

Here I have a stored procedure that inserts a row but how do you make it return the last inserted id without making another query

CREATE PROCEDURE [dbo].[spInsertCriteriaItem]
@GroupID int
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    insert into CriteriaItem (CriteriaGroupID) VALUES(@GroupID)
    --I don't want to make another query here
END

Is it possible to do this

© Stack Overflow or respective owner

Related posts about sql-server-2008

Related posts about c#