Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SELECT DISTINCT with UniqueIdentifier

Author  Topic 

tejo_pan
Starting Member

10 Posts

Posted - 2005-08-01 : 17:08:53
Dears, how can I to take the first register (MIN(My_UI)) where My_UI as UniqueIdentifier?

ex.:
SELECT DISTINCT Column1, MIN(My_UI) FROM Table GROUP BY Column1

But, if I set MIN, the SQL Server says "The minimum aggregate operation
cannot take a uniqueidentifier data type as an argument."

Thank you...

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-08-01 : 17:18:38
you can only use comparison operators (=, <>, <, >, <=, >=) or check for NULL on uniqueidentifier columns.

You cannot ORDER BY that column so TOP is out. It is really pretty limiting.

Maybe a uniqueidentifier is not needed for your column, why are you using uniqueidentifier instead of a identity column?



-ec
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-08-01 : 17:21:51
SELECT TOP 1 Column1, My_UI FROM Table GROUP BY Column1

Or cast the uniqueidentifier to char(36), and do MIN on that.

rockmoose
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2005-08-01 : 17:24:54
You have a couple of work arounds...

1) CAST the GUID to a string..
2) Apply the CHECKSUM operator to it....

DavidM

A front-end is something that tries to violate a back-end.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-08-01 : 17:33:46
quote:
Originally posted by rockmoose

SELECT TOP 1 Column1, My_UI FROM Table GROUP BY Column1

Or cast the uniqueidentifier to char(36), and do MIN on that.

rockmoose



the cast solution works. Good call.



-ec

Go to Top of Page

jeffreymfischer
Starting Member

10 Posts

Posted - 2009-10-07 : 11:21:02
You should use my solution instead of a uniqueidentifier (not a SQL friendly data type). I've written a detailed article on an enterprise-ready unique identifier solution.

http://blog.scoftware.com/post/2009/08/29/SQL-Server-UniqueIdentifier-Globally-Unique-Globally-Sequential-SOLUTION.aspx

Read it and provide feedback.

Jeff Fischer

Scoftware Achitect/Developer
http://blog.scoftware.com

Scoftware Achitect/Developer
http://blog.scoftware.com
Go to Top of Page
   

- Advertisement -