Re: Random sort via SQL in ASP
- From: "Don Leverton" <leveriteNoJunkMail@xxxxxxxxxxxxxxx>
- Date: Sat, 14 Apr 2007 17:38:44 GMT
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.Name@xxxxxxxxx
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.spam.tom7744@xxxxxxx> wrote in message
news:db1v13lq2sn06ic344tbjrf9nakp1elf6m@xxxxxxxxxx
On 12 Apr 2007 21:49:26 -0700, "muskie" <google@xxxxxxxxxxxxxxxx>
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...@xxxxxxxxxxxx wrote:
On Apr 12, 9:13 pm, eng...@xxxxxxxxxxxx wrote:
On Apr 12, 7:33 pm, "muskie" <goo...@xxxxxxxxxxxxxxxx> wrote:
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?
.
- References:
- Random sort via SQL in ASP
- From: muskie
- Re: Random sort via SQL in ASP
- From: engles
- Re: Random sort via SQL in ASP
- From: engles
- Re: Random sort via SQL in ASP
- From: muskie
- Re: Random sort via SQL in ASP
- From: Tom van Stiphout
- Random sort via SQL in ASP
- Prev by Date: Re: Unhandled errors; public vars/classes lose scope??
- Next by Date: Re: Sorting Help
- Previous by thread: Re: Random sort via SQL in ASP
- Next by thread: Pass Through Queries
- Index(es):
Relevant Pages
|