Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2008, 12:22 PM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default Random recordset

halo there.., i need some help on writing tis SQL.
i got a set of records in a table A.
i wan to query out a set of random record which consist of 10records. how can i query it? one more thing is, everytime when i refresh from my front page, the record will change? liek the dynamic random image display. plz help.

 
Old March 7th, 2008, 01:16 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

SELECT TOP 10 *
FROM TableA
ORDER BY NEWID()

Large number of records in TableA will take a long time because of the unindexed order by.

--Jeff Moden
 
Old March 8th, 2008, 12:50 AM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Jeff Moden,
tis sql just will select the top 10 of the records, how can i do when i refresh a page in the front page, it will choose another set of records? tis can solve? thank you

 
Old March 8th, 2008, 12:03 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

The code above will select a different 10 rows randomly (provided there's more than 10 rows, of course) every time it is used. I don't know how to use it from Front Page but I suspect that, like any other GUI code, there is a way to build a record set either from a stored procedure or embedded SQL.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
Selecting a Random Recordset gmoney060 Classic ASP Basics 5 October 8th, 2004 03:47 AM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.