By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

Random sort via SQL in ASP

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.