I should start by saying that SQL is not my string suit. I can write basic queries but am at a loss when it comes to things like this. After reading the FAQ secion of this forum I saw how to grab random records from a table:
My question is how can I select a random sampling of a certain database field and make sure I get a minimum amount of lets say 10 of each code in a field and also base this selection on whether or not another field contains lets say an 'X'? I guess that this really should be an insert statement as what I really want to do is write data into another database field in the same table based on a random selection with a max of 10 records per code and an 'X' in another field in the database.
Ex.-
Table has the following information:
Name Address1 Address2 City State Zip XFieldX YOutputFieldY
In this test example I want randomly select a minimum of 10 records from each state that contain an 'X' in XFieldX and then insert a 'Y' in YOutputFieldY.
I hope I explained this good enough. I have found a way to do this in our proprietary software but it is tedious and very time consuming. Any help is greatly appreciated. Thanks.
Swi
Code:
select top X from yourtable
order by rnd(numericalfield)
My question is how can I select a random sampling of a certain database field and make sure I get a minimum amount of lets say 10 of each code in a field and also base this selection on whether or not another field contains lets say an 'X'? I guess that this really should be an insert statement as what I really want to do is write data into another database field in the same table based on a random selection with a max of 10 records per code and an 'X' in another field in the database.
Ex.-
Table has the following information:
Name Address1 Address2 City State Zip XFieldX YOutputFieldY
In this test example I want randomly select a minimum of 10 records from each state that contain an 'X' in XFieldX and then insert a 'Y' in YOutputFieldY.
I hope I explained this good enough. I have found a way to do this in our proprietary software but it is tedious and very time consuming. Any help is greatly appreciated. Thanks.
Swi