VBALearner
Programmer
HI,
I am hoping to do this in SQL since I already have two subreports on my report and I have to do this to four reports total.
I need to do a top 10 for one company, a top 5 for a second company, a top 3 for a third company and a top 2 for a fourth company. Is it possible to do this in SQL? If so please help.
I tried this:
SELECT TOP 10 *
FROM [Table1] WHERE [Company Number]=1
ORDER BY Variance DESC
UNION SELECT TOP 10 *
FROM [Table1]
WHERE [Company Number]=2
ORDER BY Variance DESC;
What happens is that I get the right number of selections for each company but variances for the second company get skipped over.
For example if company 2 had a variance of 30% and company 1
10th variance was 5%, the variance for 30% will not show up.
I am hoping to do this in SQL since I already have two subreports on my report and I have to do this to four reports total.
I need to do a top 10 for one company, a top 5 for a second company, a top 3 for a third company and a top 2 for a fourth company. Is it possible to do this in SQL? If so please help.
I tried this:
SELECT TOP 10 *
FROM [Table1] WHERE [Company Number]=1
ORDER BY Variance DESC
UNION SELECT TOP 10 *
FROM [Table1]
WHERE [Company Number]=2
ORDER BY Variance DESC;
What happens is that I get the right number of selections for each company but variances for the second company get skipped over.
For example if company 2 had a variance of 30% and company 1
10th variance was 5%, the variance for 30% will not show up.