Pages

May 26, 2011

How to insert a Guid or UniqueIdentifier and return it as a OUTPUT parameter + StoredProcedure. + SQL


CREATE PROCEDURE [test]
    @name as varchar(50),
    @id as uniqueidentifier OUTPUTAS
BEGIN
    declare @returnid table (id uniqueidentifier)

    INSERT INTO test(
        name
    )
    output inserted.id into @returnid
    VALUES(
        @name
    )

    select @id = r.id from @returnid rEND
Above SP returns the newly inserted GUID as the OUT parameter.

No comments: