stored procedure with string return value, select via EXEC?

  • I have a stored procedure that generates a random string. I want to assign the result to a new variable @newstring, but am not sure how...

    I searched for storedprocs return values, but it seems to be only possible to return integer values.

    ALTER PROCEDURE [dbo].[_generateRandomString]

    @length int

    ,@validcharacters nvarchar(50)

    AS

    BEGIN

    ...

    END

    declare @newstring nvarchar(50)

    EXEC _generateRandomString 10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

  • You need to use an OUTPUT parameter.

    ALTER PROCEDURE [dbo].[_generateRandomString]

    @length int

    ,@validcharacters nvarchar(50)

    ,@randomstring nvarchar(50) OUTPUT

    AS

    BEGIN

    ...

    END

    declare @newstring nvarchar(50)

    EXEC _generateRandomString 10, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', @newstring OUTPUT

  • Awesome! It works! 🙂

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply