Solved

SQL Server convert Guid to String

Posted on 2011-03-08
3
1,334 Views
Last Modified: 2012-05-11
This would work but I am getting an error because my Users.Id (guid) is different from Users.Username (varchar).  Can I use CAST somehow to compare these as 2 strings?

DELETE S FROM [DatabaseName].[dbo].[Sessions] as S
	INNER JOIN [DatabaseName].[dbo].[Users] as U on S.UserId = U.Id
    WHERE U.Id = U.Username
GO

Open in new window

0
Comment
Question by:Midwest
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 35069958
DELETE S FROM [DatabaseName].[dbo].[Sessions] as S
      INNER JOIN [DatabaseName].[dbo].[Users] as U on S.UserId = U.Id
    WHERE cast(U.Id as char(36)) = U.Username
GO
0
 

Author Closing Comment

by:Midwest
ID: 35070007
Very nice!
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35070037
...
    WHERE CONVERT(varchar(255), U.Id) = U.Username
...
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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