Article View: be.comp.programming
Article #7153Re: [SQL Server] Random recordset terugkrijgen op select
From: SLE
Date: Thu, 17 Oct 2002 14:34
Date: Thu, 17 Oct 2002 14:34
34 lines
2600 bytes
2600 bytes
"Tom Discart" <nospam_tom.discart@pandora.be> schreef in bericht
news:XCzr9.3769$P93.497539197@hestia.telenet-ops.be...
> Ik zou graag een random recordset terugkrijgen uit een select op SQLServer
> 7.
> Het zou volgens
>
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_10350443.ht
> ml#1 op deze manier kunnen.
> SELECT * FROM tablename ORDER BY RAND()
>
> Maar... bij mij krijg ik steeds dezelfde recordset terug.
> Hoe zou ik dit op kunnen oplossen?
Uit SQL Server Books Online:
A common way to generate random numbers from RAND is to include something
relatively variable as the seed value, such as adding several parts of a
GETDATE:
SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
When you use an algorithm based on GETDATE to generate seed values, RAND can
still generate duplicate values if the calls to RAND are made within the
interval of the smallest datepart used in the algorithm. This is especially
likely if the calls to RAND are included in a single batch. Multiple calls
to RAND in a single batch can be executed within the same millisecond, which
is the smallest increment of DATEPART. In this case, incorporate a value
based on something other than time to generate the seed values.
--
SLE
Technical Details
Message-ID:
<3daeca76$0$6017$ba620e4c@news.skynet.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!proxad.net!proxad.net!opentransit.net!newsfeed.online.be!skynet.be!skynet.be!louie!not-for-mailReferences:
<XCzr9.3769$P93.497539197@hestia.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107324,886da2ec7c098b3e X-Google-Attributes: gid107324,public X-Google-Thread: 111b97,886da2ec7c098b3e X-Google-Attributes: gid111b97,public X-Google-Thread: fcea4,886da2ec7c098b3e X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2002-10-17 07:38:03 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!proxad.net!proxad.net!opentransit.net!newsfeed.online.be!skynet.be!skynet.be!louie!not-for-mail From: "SLE" <infoNOSPAM@proit.be> Newsgroups: be.comp.programming,nl.comp.programmeren,nl.internet.www.server-side References: <XCzr9.3769$P93.497539197@hestia.telenet-ops.be> Subject: Re: [SQL Server] Random recordset terugkrijgen op select Date: Thu, 17 Oct 2002 16:34:25 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Lines: 36 Message-ID: <3daeca76$0$6017$ba620e4c@news.skynet.be> Organization: -= Skynet Usenet Service =- NNTP-Posting-Host: 194.78.207.108 X-Trace: 1034865270 reader0.news.skynet.be 6017 194.78.207.108 X-Complaints-To: abuse@skynet.be