Conversion failed when converting from a character string to uniqueidentifier.

  • Greetz!

    I'm trying to use a uniqueidentifier in a where clause and I've been unable to get past this error

    (Conversion failed when converting from a character string to uniqueidentifier.).

    select AW.FullUrl, AW.Title from Features F

    inner join AllWebs AW on AW.SiteId = F.SiteId

    where F.FeatureID = '67c99ac0-5f5f-4a92-afce-eaa9ba1070e'

    The SiteId columns are also uniqueidentifiesr.

    Is it possible to do this in a query?

    Thank you!

    Even as a mother protects with her life
    Her child, her only child,
    So with a boundless heart
    Should one cherish all living beings;

  • MothInTheMachine (12/13/2011)


    Greetz!

    I'm trying to use a uniqueidentifier in a where clause and I've been unable to get past this error

    (Conversion failed when converting from a character string to uniqueidentifier.).

    select AW.FullUrl, AW.Title from Features F

    inner join AllWebs AW on AW.SiteId = F.SiteId

    where F.FeatureID = '67c99ac0-5f5f-4a92-afce-eaa9ba1070e'

    The SiteId columns are also uniqueidentifiesr.

    Is it possible to do this in a query?

    Thank you!

    Yes that is possible when the string you are using is a valid uniqueidenitfier. The string you are using in you where clause is not valid. It is missing a character in the last piece. Character length in each segment (8-4-4-12), you have (8-4-4-11).

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • oh man...ha ha ha..I really need to work on my troubleshooting skills!

    Thanks so much!

    Even as a mother protects with her life
    Her child, her only child,
    So with a boundless heart
    Should one cherish all living beings;

  • If you want to avoid this in future, get into the habit of specifying a typed UNIQUEIDENTIFIER rather than a string. Either use the curly brace format, or an explicit CONVERT:

    PRINT {guid '67c99ac0-5f5f-4a92-afce-eaa9ba1070e'}

    GO

    PRINT CONVERT(UNIQUEIDENTIFIER, '67c99ac0-5f5f-4a92-afce-eaa9ba1070e')

    GO

    PRINT {guid '67c99ac0-5f5f-4a92-afce-eaa9ba1070e1'}

    GO

    PRINT CONVERT(UNIQUEIDENTIFIER, '67c99ac0-5f5f-4a92-afce-eaa9ba1070e1')

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

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