Re: Selecting random rows from a dataset



Kudos to Steve Kass, i've seen this in one of his posts, I tested it and it
works perfectly:

-- Manual Bernoulli sampling
SELECT RAND(CHECKSUM(NEWID())%1000000000+CustomerKey),*
FROM vTargetMail
WHERE RAND(CHECKSUM(NEWID())%1000000000+CustomerKey)< 0.1
-- 0.1 is the desired probability of choosing a row, change as needed.
GO


--
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com


"dataGirl" <dataGirl@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0D2BE4C3-E51D-4D80-A0F6-90BC12553600@xxxxxxxxxxxxxxxx
> Question: If I have created a select statement that returns all possible
> values, can I step through this list using SQL to get a random selection
> of
> 10% of the rows? If so, what commands should I be looking at? The
> closest
> I've came was to get the top 10%. However, I do not want just the top
> 10%, a
> want a random selection. If this can't be done using SQL commands, are
> there
> any suggestions for an alternate method?
>
> Thanks


.



Relevant Pages

  • Re: Adding Rows to Data-Bound DataGridView
    ... "Fill,GetData" SQL commands), I created an Insert and an Update SQL command. ... If you use the DataAdapter or generated TableAdapter Update method, ... Hitchhiker’s Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: How I can sysnchronize changes in DataTable with my Database?
    ... Normaly we a not able to made changes when is no connection. ... I like SQL but I would like to learn some other approach to change data. ... >> What is the purpose of this apporach if we use plain SQL commands? ... > the database within a single method call. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I issue SQL to a Access database from command line
    ... you can query the MSysObjects table. ... will give you all of the tables in the database. ... > window like SQLPLUS or ISQL/W which will enable me to run SQL commands ...
    (microsoft.public.access.externaldata)
  • Re: Accuracer Database
    ... take the first example where NexusDB 'failed': ... Does standard SQL allow you to order by a field not in the result set? ... particular chosen set of SQL commands. ... Now, I put it to you that if you were a database vendor, you could very ...
    (borland.public.delphi.thirdpartytools.general)
  • sql build cmd uses [ and ] but I need "
    ... Was wondering if there is some setting in VS2005 where it can build my sql commands using that postgresql quote instead of brackets. ... Createing a SqlDataSource and using this bible reference: ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)