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 2005 Forums
 Transact-SQL (2005)
 Kinda stupid question but I can't figure it out.

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2007-12-30 : 21:28:10
I tried using the search to find the answer but they all referance doing it with a numbered column. What I want to is open Table and return a single random row of data. I would use the Random command but that deals with numbers and there is no number row. All data has an Alpha based name. Any suggestions?

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-30 : 22:29:03
SELECT TOP 1 *
FROM YourTable
ORDER BY NEWID()

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2007-12-31 : 11:31:40
Thanks, I ran across that code in my search but it did not have the newid() tag.

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-31 : 23:18:52
It's new function in sql2k5.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-01-01 : 03:28:06
NEWID() isn't new to 2005. It was available in 2000 too.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -