Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 August 1st, 2004, 12:15 AM
Authorized User
 
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me !

Could you tell me how to Select random a SQL statement from VB 6.0

 
Old August 1st, 2004, 11:25 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

I am sorry, but I could not understand your requirement. Could you please explain it in details ? What do you mean by "Select random a SQL statement" ?
 
Old August 2nd, 2004, 12:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

get the number of records, and generate a random number using rnd:

lRecordToRead = fix(rnd * lTotalRecords)

then move to lRecordToRead

Marco
 
Old August 2nd, 2004, 04:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Do you want to select a random row from an SQL Query?

If so, and you are using SQL Server, try:
Code:
SELECT TOP 1 yourcolumn1, yourcolumn2, ...
FROM yourtable
ORDER BY NEWID();
The NEWID() function generates a GUID for each row in your query. Guids are random, unique values, so ordering the results of your query by this random number and then selecting just one row gives you one random row from the entire query.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com









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