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)
 Using TOP in SELECT statement

Author  Topic 

Mazdak
Yak Posting Veteran

63 Posts

Posted - 2004-08-25 : 11:09:39
I have a table which its primary key is uniqueidentifier. I want to use query which retuen top 10 order by the order they've added to table. If my primary key is autonumbered I could use TOP 10 in my select but what about uniqueidentifier?

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-25 : 11:12:27
that's a bit harder. in order to do that you'll need another column DateAdded and put a default value of GetDate() on it.
this way you will have the ability to order it properly.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2004-08-25 : 11:12:43
Uniqueidentifier is GUID and so they are assigned in a random order. You'll need to create a column for the date added and populate it with the system date.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

Mazdak
Yak Posting Veteran

63 Posts

Posted - 2004-08-25 : 11:15:42
Thanks to both of you.
Go to Top of Page
   

- Advertisement -