I have a query that returns 20 columns, I want to get 10 random records (or
all if less than 10) for the first 10 columns for each possible combination.
Anyone have an easy way of doing this?
Sample Data: (5 columns, based on first 3 columns, getting 2 random
records)
01 01 A Testing Record1
02 01 A Testing Record2
01 04 B Testing Record3
01 01 A Testing Record4
02 01 B Testing Record5
03 01 A Testing Record6
01 03 A Testing Record7
01 01 B Testing Record8
01 01 A Testing Record9
01 03 B Testing Record10
03 01 A Testing Record11
01 01 B Testing Record12
02 01 A Testing Record13
01 04 B Testing Record14
01 01 B Testing Record15
01 03 A Testing Record16
02 01 B Testing Record17
01 02 A Testing Record18
02 01 A Testing Record19
01 02 A Testing Record20
So in this example I would want:
01 01 A Testing Record1
01 01 A Testing Record4
01 01 B Testing Record8
01 01 B Testing Record12
01 02 A Testing Record18
01 02 A Testing Record20
01 03 A Testing Record7
01 03 A Testing Record16
01 03 B Testing Record10
01 04 B Testing Record3
01 04 B Testing Record14
02 01 A Testing Record13
02 01 A Testing Record19
02 01 B Testing Record5
02 01 B Testing Record17
03 01 A Testing Record6
03 01 A Testing Record11
Using the logic mentioned, I would lose 3 records, since 3 had at least 3
record groups. AND for Record10, I only have one record because the
combination only existed once.
This electronic message transmission contains information from the Company that may be proprietary, confidential and/or privileged.
The information is intended only for the use of the individual(s) or entity named above. If you are not the intended recipient, be
aware that any disclosure, copying or distribution or use of the contents of this information is prohibited. If you have received
this electronic transmission in error, please notify the sender immediately by replying to the address listed in the "From:" field.
MS Sql Server LazyDBA home page