?
Solved

Syntax error converting from a character string to uniqueidentifier.

Posted on 2005-03-15
5
Medium Priority
?
1,249 Views
Last Modified: 2012-08-13
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
Comment
Question by:pmengal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
Otana earned 1500 total points
ID: 13543524
SELECT DisplayName, UserGUID FROM Profiles, Requests WHERE cast(Profiles.UserGUID as nvarchar(100)) = Requests.UserGUID
0
 

Author Comment

by:pmengal
ID: 13543578
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
 
LVL 11

Expert Comment

by:Otana
ID: 13543607
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
 

Author Comment

by:pmengal
ID: 13543667
Thanks for that!
0
 
LVL 11

Expert Comment

by:Otana
ID: 13543699
You're welcome.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question