473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Random sort via SQL in ASP

I've looked through as many posts about this as possible, but all end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:

SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;

where TableID is an autonumber field.

I've seen references to Randomize, but how do you use Access's
randomize from ASP?

Does anyone know of a simple solution for this?

Thanks,
Matt

Apr 13 '07 #1
5 8138
On Apr 12, 7:33 pm, "muskie" <goo...@sniderstudio.comwrote:
I've looked through as many posts about this as possible, but all end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:

SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;

where TableID is an autonumber field.

I've seen references to Randomize, but how do you use Access's
randomize from ASP?

Does anyone know of a simple solution for this?

Thanks,
Matt
I'd be surprised if you can use this in SQL using the method you are
trying. I'd write some code that you can trigger that puts a random
number in a field (e.g. sortfield as long) in the table. Then you can
select and order by that random field (e.g. ORDER BY sortfield). This
will certainly get the job done. Whenever you want a different
randomizing, then trigger the code.

-- Larry Engles

Apr 13 '07 #2
On Apr 12, 9:13 pm, eng...@ridesoft.com wrote:
On Apr 12, 7:33 pm, "muskie" <goo...@sniderstudio.comwrote:


I've looked through as many posts about this as possible, but all end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:
SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;
where TableID is an autonumber field.
I've seen references to Randomize, but how do you use Access's
randomize from ASP?
Does anyone know of a simple solution for this?
Thanks,
Matt

I'd be surprised if you can use this in SQL using the method you are
trying. I'd write some code that you can trigger that puts a random
number in a field (e.g. sortfield as long) in the table. Then you can
select and order by that random field (e.g. ORDER BY sortfield). This
will certainly get the job done. Whenever you want a different
randomizing, then trigger the code.

-- Larry Engles- Hide quoted text -

- Show quoted text -
If you have an autonumber feild, you could use that in the query (e.g.
ORDER BY (autonumberField).
-- Larry Engles

Apr 13 '07 #3
On Apr 12, 10:40 pm, eng...@ridesoft.com wrote:
On Apr 12, 9:13 pm, eng...@ridesoft.com wrote:
On Apr 12, 7:33 pm, "muskie" <goo...@sniderstudio.comwrote:
I've looked through as many posts about this as possible, but all end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:
SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;
where TableID is an autonumber field.
I've seen references to Randomize, but how do you use Access's
randomize from ASP?
Does anyone know of a simple solution for this?
Thanks,
Matt
I'd be surprised if you can use this in SQL using the method you are
trying. I'd write some code that you can trigger that puts a random
number in a field (e.g. sortfield as long) in the table. Then you can
select and order by that random field (e.g. ORDER BY sortfield). This
will certainly get the job done. Whenever you want a different
randomizing, then trigger the code.
-- Larry Engles- Hide quoted text -
- Show quoted text -

If you have an autonumber feild, you could use that in the query (e.g.
ORDER BY (autonumberField).
-- Larry Engles
Thanks Larry, I appreciate the input...
If I run my query in Access it works to produce a randomly sorted
recordset. If I run the exact same query from my ASP it does not.
Any idea why this happens?

Apr 13 '07 #4
On 12 Apr 2007 21:49:26 -0700, "muskie" <go****@sniderstudio.com>
wrote:

Because when running from Access you have the entire Access VBA code
available (including the Rnd function), whereas when running from ASP
you only have the Jet database engine.

If you only want to select one or a few random records, perhaps you
can open a recordset, count the records, and then rs.Move a random
number between 1 and RecCount from the top.

In SQL Server you can use NewID to sort with.

-Tom.

>On Apr 12, 10:40 pm, eng...@ridesoft.com wrote:
>On Apr 12, 9:13 pm, eng...@ridesoft.com wrote:
On Apr 12, 7:33 pm, "muskie" <goo...@sniderstudio.comwrote:
I've looked through as many posts about this as possible, but all end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:
SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;
where TableID is an autonumber field.
I've seen references to Randomize, but how do you use Access's
randomize from ASP?
Does anyone know of a simple solution for this?
Thanks,
Matt
I'd be surprised if you can use this in SQL using the method you are
trying. I'd write some code that you can trigger that puts a random
number in a field (e.g. sortfield as long) in the table. Then you can
select and order by that random field (e.g. ORDER BY sortfield). This
will certainly get the job done. Whenever you want a different
randomizing, then trigger the code.
-- Larry Engles- Hide quoted text -
- Show quoted text -

If you have an autonumber feild, you could use that in the query (e.g.
ORDER BY (autonumberField).
-- Larry Engles

Thanks Larry, I appreciate the input...
If I run my query in Access it works to produce a randomly sorted
recordset. If I run the exact same query from my ASP it does not.
Any idea why this happens?
Apr 13 '07 #5
How about adding a Long Integer field to the table itself called "NewID",
and then run an update query to fill this field with random ID's on a
somewhat "permanent basis" ?
Sort your data by NewID for use in your ASP.
To re-randomize the values at any time ... run the update query again.
--
--
HTH,
Don
=============================
E-Mail (if you must) My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code samples are also Access97- based
unless otherwise noted.

================================================== ========================

"Tom van Stiphout" <no*************@cox.netwrote in message
news:db********************************@4ax.com...
On 12 Apr 2007 21:49:26 -0700, "muskie" <go****@sniderstudio.com>
wrote:

Because when running from Access you have the entire Access VBA code
available (including the Rnd function), whereas when running from ASP
you only have the Jet database engine.

If you only want to select one or a few random records, perhaps you
can open a recordset, count the records, and then rs.Move a random
number between 1 and RecCount from the top.

In SQL Server you can use NewID to sort with.

-Tom.

>>On Apr 12, 10:40 pm, eng...@ridesoft.com wrote:
>>On Apr 12, 9:13 pm, eng...@ridesoft.com wrote:

On Apr 12, 7:33 pm, "muskie" <goo...@sniderstudio.comwrote:

I've looked through as many posts about this as possible, but all
end
with no resolution. I simply need records from a table in random
order, and I will be calling this recordset in a SQL statement from
ASP. I've tried the following but it does not produce random order:

SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC;

where TableID is an autonumber field.

I've seen references to Randomize, but how do you use Access's
randomize from ASP?

Does anyone know of a simple solution for this?

Thanks,
Matt

I'd be surprised if you can use this in SQL using the method you are
trying. I'd write some code that you can trigger that puts a random
number in a field (e.g. sortfield as long) in the table. Then you can
select and order by that random field (e.g. ORDER BY sortfield). This
will certainly get the job done. Whenever you want a different
randomizing, then trigger the code.

-- Larry Engles- Hide quoted text -

- Show quoted text -

If you have an autonumber feild, you could use that in the query (e.g.
ORDER BY (autonumberField).
-- Larry Engles

Thanks Larry, I appreciate the input...
If I run my query in Access it works to produce a randomly sorted
recordset. If I run the exact same query from my ASP it does not.
Any idea why this happens?

Apr 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jefferis NoSpamme | last post by:
I have a query that is showing new items in a store based upon their inventory date. The problem with my Random order sort is that when the "next" link is pressed, the random function is called...
1
by: Brandon Michael Moore | last post by:
I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a...
4
by: Frank & Janny Plaza | last post by:
I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort this list of names several times and then show the order in...
7
by: Jean-Francois.Doyon | last post by:
Hello, I'm trying to retrieve a limited number of random rows, and order them by a column, and am not having any luck with that last part: SELECT * FROM tablename ORDER BY random(), id LIMIT...
10
by: Johnny Snead | last post by:
Hey guys, Need help with this random sort algorithm private void cmdQuestion_Click(object sender, System.EventArgs e) { Random rnd = new Random(); //initialize rnd to new random object...
9
by: gl | last post by:
How do I take an array or arraylist, and sort it randomly? Like suppose the items in it are (1,2,3,4,5) and I want to get it to be in a random order (2,3,1,4,5). How do you do that? I think it's a...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
19
by: Boris Borcic | last post by:
does x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) pick a random shuffle of x with uniform distribution ? Intuitively, assuming list.sort() does a minimal number of comparisons to ...
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.