Converting GUID to varchar

  • Hi All,

    Its very urgent,Please can anyone help on this.

    I have created a stored procedure to take UniqueIdentifier as parameter. I'm not able to pass UnqiueIdentifier value directly, hence I'm passing the value as varchar to stored procedure. In the stored procedure am converting the varchar to Unique Identifier, howevet it is giving error like "Syntax error converting from a character string to uniqueidentifier"

    Id='42055BA3-8942-497A-8343-6B2FE9ACD48'

    CREATE PROCEDURE [dbo].[verify_sp]

    @userid Ident,

    @Id Varchar(50)

    as

    Begin

    select @AuthId=cast(@Id as UniqueIdentifier)

    IF NOT EXISTS(select * from table1 where Id=@AuthId)

    Begin

    Raiserror (50004,11,1)

    return 0

    End

    End

    return 0

    GO

    Cheers,

    nandy

  • Hi There,

    You can convert it like this:

    DECLARE @RR as uniqueidentifier

    SET @RR = CONVERT(uniqueidentifier, '5617317D-3D3A-430C-956C-34585EC7964B')

    Print @RR

    BTW: Your ID is not a valid uniqueidentifier it missing a character at the last part :satisfied:

  • Hi there,

    Thanks a ton Now I can able to convert the value.

    Cheers,

    nandy

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

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