You would need to provide some unique value to determine which X. Are you looking for random records? If so, you would need to add a random calculation into your query.
No sample data? No desired output? That's not much to go on. Typically I would create a calculated column that sequentially numbers records within a VERSION and then select all records with the sequence number less than or equal to X.
SEQ, NAME, ADDR, CSZ, VERSION
1,John1 Doe,1 Any St.,Anytown US 11111,A
2,John2 Doe,2 Any St.,Anytown US 22222,A
3,John3 Doe,3 Any St.,Anytown US 33333,B
4,John4 Doe,4 Any St.,Anytown US 44444,B
5,John5 Doe,5 Any St.Anytown US 55555,C
In a quick example, I would like to return the following if the user chose to have 1 record of each but they would have the option to choose how many of they would like to pull for each VERSION.
1,John1 Doe,1 Any St.,Anytown US 11111,A
3,John3 Doe,3 Any St.,Anytown US 33333,B
5,John5 Doe,5 Any St.Anytown US 55555,C
Now, loop thru the outcome from above and build this SQL:
SELECT TOP (1) * FROM MyTable Where VERSION = 'A'
UNION ALL
SELECT TOP (1) * FROM MyTable Where VERSION = 'B'
UNION ALL
SELECT TOP (1) * FROM MyTable Where VERSION = 'C'
Run this multi-select statement and you should get what you want.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.