UniqueIdentifier parameter in sql

  • I've created procedure

    Create procedure [dbo].[Options] @COMPANY_ID varchar

    as

    declare @company_IdUnique uniqueidentifier

    --The reason why iam converting below is i have to insert the row into the table in which companyId is uniqueidentifier.

    set @company_IdUnique = cast(@COMPANY_ID as uniqueidentifier)

    --Some SQL statements follow here

    --Test Calling the store procdure from sql

    exec CompanyOptionsFreeForm 'b7a83d8-e6d7-415f-9664-056e2ea7ea0b'

    --But it is giving the following error

    Syntax error converting from a character string to uniqueidentifier.

    --how to pass the value to the unique identifier param.

  • santosh_kollipaka (7/24/2008)


    I've created procedure

    Create procedure [dbo].[Options] @COMPANY_ID varchar

    as

    declare @company_IdUnique uniqueidentifier

    --The reason why iam converting below is i have to insert the row into the table in which companyId is uniqueidentifier.

    set @company_IdUnique = cast(@COMPANY_ID as uniqueidentifier)

    --Some SQL statements follow here

    --Test Calling the store procdure from sql

    exec CompanyOptionsFreeForm 'b7a83d8-e6d7-415f-9664-056e2ea7ea0b'

    --But it is giving the following error

    Syntax error converting from a character string to uniqueidentifier.

    --how to pass the value to the unique identifier param.

    try setting the varchar size in the porcedure declaration, otherwise it will be defaulted to varchar(1) - making your cast trying to get a GUID from 'b'

    Kev

  • Hi kev,

    Even though i set the varchar(60) , still iam getting the same error.

  • the example you give 'b7a83d8-e6d7-415f-9664-056e2ea7ea0b' isn't a valid GUID - the first part before the first hyphen needs to have 8 characters

    Kev

  • Thank you kev that is the problem , now it is solved.

  • VARCHAR defaults to 50, right? Same length as a "sysname"?

Viewing 6 posts - 1 through 5 (of 5 total)

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