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
 General SQL Server Forums
 New to SQL Server Programming
 random rows

Author  Topic 

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 00:43:01
Hi all,
I would like to select 1250 random rows in sql server using a function similar to oracle's sample function.please let me know if it is possible......
Thanks........

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-04 : 01:00:55
[code]
select TOP 1250 *
from yourtable
order by NEWID()
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 08:03:12
Thanks for the reply....As the tables are very large i do not want to use order by as it would take lot of time....Please let me know if there is any other way out (similar to oracle's sample function).
Thanks,
Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-04 : 08:42:17
if you're using sql 2008 use TABLESAMPLE

http://msdn.microsoft.com/en-us/library/ms189108.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 10:33:02
Hi Visakh,
Thanks For the reply. I have to actually do it on a linked server(attunity) and table sample does not support on linked servers.I do not know what is the syntax in Attunity.Please let me know is there any other way around which works on linked server as well.
Thanks.......
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-04 : 10:46:04
Use OPENQUERY:

select * from openquery(linkedServer,'select FirstName, LastName from AdventureWorks.Person.Contact tablesample (10 percent)')

If Attunity is based on SQL Server then this should work.
Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 11:05:14
Thanks for the reply...I have tried this earlier but Attunity is not based on SQL server and i believe it is based on ANSI SQL.Please let me know any other way...
Thanks....
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-04 : 11:22:18
Best I can suggest then is to find out which RDBMS platform it is using (Oracle, MySQL, etc.) or contact Attunity support, or go with khtan's method.
Go to Top of Page
   

- Advertisement -