Msg 8169, Level 16, State 2, Line 121 Conversion failed when converting from a character string to uniqueidentifier.

Parvinder Tomar 146 Reputation points
2022-03-08T17:45:05.853+00:00

I received the below error in the Azure SQL database, I have 6 tables with the inner joins in the query and the last join is where I am using table1.column=CAST(table2.Column AS UNIQUEIDENTIFIER) and my query fails as soon as it runs. I checked the data and there are no bad data, I am excluding the rows that are not a GUID-like.

181094-image.png

Azure SQL Database
0 comments No comments
{count} vote

Accepted answer
  1. Alberto Morillo 34,676 Reputation points MVP Volunteer Moderator
    2022-03-08T18:02:23.53+00:00

    Please try joining them by converting both sides to NVARCHAR(36).

    CAST(table1.column AS NVARCHAR(36)) =CAST(table2.Column AS NVARCHAR(36))
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.