views:

234

answers:

2

Can I return UNIQUEIDENTIFIER from a stored procedure using the RETURN statement or is it only by using the OUTPUT statement?

i.e to return the PersonID UNIQUEIDENTIFIER:

CREATE PROCEDURE CreatePerson
    @Name NVARCHAR(255), 
    @Desc TEXT
AS
DECLARE @Count INT
DECLARE @JobFileGUID UNIQUEIDENTIFIER 

-- Check if job exists?
SET @Count = (SELECT COUNT(Name) AS Name FROM Person WHERE Name=@Name)

IF @Count < 1
BEGIN
    SET @PersonGUID = NEWID();

    INSERT INTO Person 
        (PersonID, Name, [Desc]) 
        VALUES (@PersonGUID, @Name, @Desc)

END

    SELECT @PersonGUID = Person.PersonID 
    FROM Person
    WHERE Name = @Name

    RETURN @PersonGUID
GO

Thanks

A: 

In stored procedure - only using the OUTPUT statement. In function - return.

Tadas
thought that was the case... thanks
Belliez
A: 

Use:

CREATE PROCEDURE CreatePerson
    @Name NVARCHAR(255), 
    @Desc TEXT,
    @PersonGUID UNIQUEIDENTIFIER OUTPUT
AS
BEGIN

   SET @PersonGUID = ...

END
Gary McGill