convert varchar to uniqueidentifier in a stored procedure

  • I have a procedure that begins like this::

    Create Procedure dbo.SRIPContracts

    @ContractID varchar(30) = Null

    As

    If @ContractID Is Null

    @contractID = NewID()

    but this fails because of the data type conflict. I can not change the datatype of contraactaID when I declare it because the parameter is coming from a classic asp page and the QueryString is a varchar. However, I need to convert the varchar to uniqueidentifier inside the stored proc.

    Any idea?

  • Hi

    Problem seems to be the size of your varchar not the type.

    This works:

    DECLARE @v-2 VARCHAR(36);

    SELECT @v-2 = NEWID();

    This doesn't work:

    DECLARE @v-2 VARCHAR(30);

    SELECT @v-2 = NEWID();

    Greets

    Flo

  • Thank you so much. it worked.

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

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