Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Dear All,

I have a table with the column of uniqueidentifier Datatype. here i want to select the records compare with the uniqueidentifier data.

Ex:

SQL
CREATE TABLE [dbo].[Table1](
    [Id] [uniqueidentifier] NOT NULL,
    [Name] [nvarchar] (100) NOT NULL



SQL
SELECT * FROM Table1 WHERE Id <= 'A8912F3C-81BE-4076-B6AB-0000017330AD'


It's possible to select the records? please suggest me
Posted

That is a meaningless query - "less than or equal to" in Guid terms has no real meaning. What records are "less than" a Guid? Undefined, really, since Guids are not issued in any particular order. The next Guid issues could start with a '2', or a 'F', or another 'A'.

Don't try to compare Guids based on any order - the concept is meaningless for them.

What are you trying to do, that you think "<=" with Guids would be helpful?
 
Share this answer
 
Others will have to correct me if I'm wrong, but I don't believe that you can use <= or >= operators with uniqueidentifiers.

Your best bet is the equality operator:

SQL
SELECT * FROM Table1 WHERE Id = 'A8912F3C-81BE-4076-B6AB-0000017330AD'


If you want to query a range of uniqueidentifiers you could use a where.. in clause:

SQL
SELECT * FROM Table1 WHERE Id IN ('A8912F3C-81BE-4076-B6AB-0000017330AD', 'B8912F3C-81BE-4076-B6AB-0000017330AD', 'C8912F3C-81BE-4076-B6AB-0000017330AD')
 
Share this answer
 
Comments
Suresh Kumar_P 3-Dec-11 6:36am    
Hi jim,

Thanks for your valuable command. I also used the same concept as you suggest. now i got my solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900