Get programming code snippets and tips for HTML, CSS, ASP, SQL, JavaScript, RSS, XML, and more
Lee's Code        A web programmer's toolbox. SEARCH SITE
HOME  |  ABOUT LEE  |  CONTACT  |  SEARCH
Home > Code > ASP > ASP - Select Random Records from a data table

Navigation

Latest Additions

Links


 

Recommendations

Evolve Online
Powered by
Evolve Online
 

ASP - Select Random Records from a data table

By: Lee A. Shurie
 
Subject: Database Table
Language: ASP
Rating:
 Rated 57 times. Rate or review this item: 1 2 3 4 5
 Read Reviews
 
Information
Many ASP programmers write complicated code to simulate a random selection of items from an open recordset. This is often done by reading all the records into an array, then selecting 10 random records from that array. However, this method is slow and inefficient. Better to use standard features of SQL to select only the number of records needed. This script selects 10 random products from a table named products. It expects that you have already opened a database connection, identified as "c".
 
Code


 
Instructions
Place this code after you have opened a database connection using "c" as the connection.
 
Keywords:random select SQL
 

Lee's Code programming tips and tricks. Back to top of page.

Programming tips and tricks for ASP, javaScript, SQL, SML, CSS, HTML HOME | ABOUT LEE | CONTACT | SEARCH
 
Copyright © 2001 - 2010 by Lee A. Shurie