converting unique identifier.

  • I have a table that has a uniqueidentifier column - Pk_dpAdl( with newid() function . I am doing the following select. I want to select a record for a specific value in the uniqueidentifier column.

    DECLARE @Pk_dpAdl SYSNAME

    SELECT @Pk_dpAdl = 'DP8D24D87F-4B9C-11D5-B137-009027892F87'

    SELECT * FROM DpAdl WHERE Pk_dpAdl = CONVERT(uniqueidentifier,'DP8D24D87F-4B9C-11D5-B137-009027892F87')

    I am getting following error.

    Server: Msg 8169, Level 16, State 2, Line 5

    Syntax error converting from a character string to uniqueidentifier.

    How can i get rid of this error.

  • Two things:

    1. You can't have P as part of the string. It must be from A to F or a digit.

    2. The first part should be 8 chars long. You have 10.

    Try

    SELECT * FROM DpAdl WHERE Pk_dpAdl = CONVERT(uniqueidentifier,'D08D24D8-4B9C-11D5-B137-009027892F87')

  • Thanks it works

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

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