Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1258
  • Last Modified:

Syntax error converting from a character string to uniqueidentifier.

I received the following error trying to do this query

[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting from a character string to uniqueidentifier.

SELECT DisplayName, UserGUID FROM Profiles, Requests WHERE Profiles.UserGUID = Requests.UserGUID

The UserGUID field of the table Profiles is type uniqueidentifier
The UserGUID field of the table Requests is type nvarchar(100)

I can't change the type of those fields for technical reasons.

Could you help me building the right SQL query ?

Thanks !
0
pmengal
Asked:
pmengal
  • 3
  • 2
1 Solution
 
OtanaCommented:
SELECT DisplayName, UserGUID FROM Profiles, Requests WHERE cast(Profiles.UserGUID as nvarchar(100)) = Requests.UserGUID
0
 
pmengalAuthor Commented:
It worked but the problem is that in the Requests table, the GUID are stored with { }, so I will need to remove those in all the records ;)

Thanks again

0
 
OtanaCommented:
You could remove the '{}' by using REPLACE:

SELECT DisplayName, UserGUID FROM Profiles, Requests WHERE cast(Profiles.UserGUID as nvarchar(100)) = REPLACE(REPLACE(Requests.UserGUID,'{',''),'}','')
0
 
pmengalAuthor Commented:
Thanks for that!
0
 
OtanaCommented:
You're welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now