I have a table customer and 100 rows in it. a status column is set for active/inactive customer in the table.
What i want to do is to select all customers from the table in a specific order
ie
first 7 active customers then 3 inactive customers again 7 active customers and 3 inactive and so on
How can I achieve this in a query.
I am using sql server 2008 . Please Help me….
Something like this should do it, based on the minimal requirements you’ve listed so far:
Obviously, altering the table and column names as appropriate.
PKIDis assumed to be some other column in the table against which the individual rows can be ordered.The magic numbers in the AlteredOrdering CTE are hopefully obvious – 7 and 3 come from the question, and represent how many of each item should appear in each “group”. The 10 is the total size of each “group”. So if it was 9 active, 4 inactive, the CASE expression would look like: