Is there a way not to select the top so many records
of my random records. I know 20% of my records are 412 so I select the
top 412,
but is there a way to randomly select 412 records without using top?
Thank you everyone for helping me with all of your suggestions. I used
the
shortest bit of code since I had time constraints, but I'm going to
test the
cursor and non-cursor solutions as well.
Thanks again everyone. I'll continue researching this as well.
My query to get a random sample of 20% of the records:
First, I randomize all records and put them into a temporary table.
select * into random16
from bptmaster
where boardcode = '16' and YOLR = '2003' and status = 'A'
order by newid()
Then I re-randomize and select the top 412 records.
select top 412 * into randomd16
from random16
order by newid()
MS Sql Server LazyDBA home page