473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Select where uniqueidentifier = 0x hex?

Hi all,

I'm trying to run a select where a
uniqueidentifier/GUID equals a hex, but I don't seem to be getting
matches.

For example, this query returns the expected record:
select * from items where itemGUID =
'{11111111-2222-3333-4444-555555555555}'

But this one does not:
select * from items where itemGUID = 0x11111111222233334444555555555555

Any tips?

thanks, -Scott

Aug 22 '05 #1
5 18912

just try and convert the datatype to varbinary

best Regards,
Chandra
http://www.SQLResource.com/
http://chanduas.blogspot.com/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Aug 22 '05 #2
Do you know if it is possible to do a 0x style lookup from a
uniqueidentifier column?

My understanding was that uniqueidentifier is basically a binary(16) --
and so I thought I could use both {GUID} and 0x to perform a lookup...

thanks, -Scott

Aug 22 '05 #3
turnstyle (sc***@turnstyle.com) writes:
I'm trying to run a select where a
uniqueidentifier/GUID equals a hex, but I don't seem to be getting
matches.

For example, this query returns the expected record:
select * from items where itemGUID =
'{11111111-2222-3333-4444-555555555555}'

But this one does not:
select * from items where itemGUID = 0x11111111222233334444555555555555


This is because the bytes are rearranged in the textual representation.
Here is an example that works:

CREATE TABLE t (guid uniqueidentifier NOT NULL)
INSERT t (guid) VALUES ('35ADD319-FEA5-443B-8628-0FD8588BE6DA')
SELECT * FROM t
SELECT * FROM t WHERE guid = 0x19D3AD35A5FE3B4486280FD8588BE6DA
go
DROP TABLE t
That is, in the first three groups, the byte order should be reversed.
So, yes, you can do it. Question is only: should you?
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 22 '05 #4
> the bytes are rearranged in the textual representation.

ugh, that seems like a pretty odd design (and I'll bet I'm not the
first to say so.. ;)

Just curious -- is there a general opinion regarding whether it's
better to store GUIDs in a uniqueidentifier or a binary(16)?

The binary(16) seems to return a binary result whereas the
uniqueidentifier seems to return a string of the hex equivalent, and
what I need is that string -- is there a simple way to select a
binary(16) and get the hex string back?

thanks, -Scott

Aug 23 '05 #5
turnstyle (sc***@turnstyle.com) writes:
Just curious -- is there a general opinion regarding whether it's
better to store GUIDs in a uniqueidentifier or a binary(16)?
I don't know if there is a general opinion, but personally I can see
no point in stored a GUID as a binary(16) where there is a built-in
data type.
The binary(16) seems to return a binary result whereas the
uniqueidentifier seems to return a string of the hex equivalent, and
what I need is that string -- is there a simple way to select a
binary(16) and get the hex string back?


Depends on what you mean with simple. But since there is no built-in
documented function for writing a binary value as a hex string into a
character value, and you also need to use substring(), I would say that
you would only do this if you like to hurt yourself.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jacques Wentworth | last post by:
Hi I have the following problem. I have a SQL Server (2000) Stored Proc that with 4 parameter (one being @UnlockKey uniqueidentifier OUTPUT). I run it from Query Analyzer and the @Key parameter...
2
by: Carl | last post by:
Hi, I do have one dataset from SQL server with a field (bound) to Textbox called txtID , this field is of type uniqueidentifier. From the doc, they say the equivalent is GUID in dot net, ...
3
by: SMG | last post by:
Hi all, I created one table with following structure, and bound the same with a DataGird. But I am not able to see any column which is having 'uniqueidentifier' as datatype. Name ...
1
by: Scott M. Lyon | last post by:
I've got a stored procedure that takes a few parameters as input parameters, and one output parameter (a uniqueidentifier). After the stored procedure call, I need to return that output parameter...
1
by: Scott M. Lyon | last post by:
I've got a stored procedure that takes a few parameters as input parameters, and one output parameter (a uniqueidentifier). After the stored procedure call, I need to return that output parameter...
1
by: dawg1998 | last post by:
I am attempting to create a record that has a uniqueidentifier datatype. I am receiving the following error each time I attempt the Insert: Incorrect syntax near '-' The following is the code...
5
by: John | last post by:
I just cannot manage to perform a SELECT query with NULL parameter... My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB null value). TCATEGORYID and TCATEGORYPARENTID...
5
by: DotNetNewbie | last post by:
Hi, I am developing an application that has to scale and be very efficient, and I am using asp.net membership in my application. I set things up in my Users table (it has extra columns that I...
8
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Vb.net 2005 app I am looking up records in a sql 2005 database and I grab the uniqueidentifier and put it into a variable (gID) of type GUID. When I try to create a new record in a new table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.