November 22, 2004 at 7:40 am
I am working on a report Which would be like following
This is what i have:
company_no dept_no count
1 2 10
1 3 11
1 4 39
2 1 15
3 2 99
3 3 74
I would like to show this data as below:
company_no dept_no count
1 1 0
1 2 10
1 3 11
1 4 39
2 1 15
2 2 0
2 3 0
2 4 0
3 1 0
3 2 99
3 3 74
3 4 0
How can I do this.
Thanks.
November 22, 2004 at 8:09 am
Hi,
What exactly you want to show on report?do u wnat to repeat dept_no with count? or just count for each dept_no?
November 22, 2004 at 8:13 am
SELECT
FROM
ORDER BY company_no dept_no
Have fun
Steve
We need men who can dream of things that never were.
November 22, 2004 at 8:22 am
For each company we have 4 departments.
Suppose for company 1 we have 2 departments and 2 and 3 and they have dept_no_count is 23 and 34 respectively.
But in my report If I group the data the repprt would be like this
company_id dept_no dept_no count
1 2 23
1 3 34
Because i dont have dara for dept 1 and 4.
But i shoul have a report like
company_id dept_no dept_no count
1 1 0
1 2 23
1 3 34
1 4 0
Thanks.
November 22, 2004 at 8:26 am
Do you have a table listing departments for each company?
Assuming there are always 4 depts for each company as in your example:
SELECT counts.company_no, counts.dept_no, counts.count
FROM (
SELECT dept_no = 1
UNION SELECT dept_no = 2
UNION SELECT dept_no = 3
UNION SELECT dept_no = 4
) depts
left join counts on (counts.dept_no = depts.dept_no)
ORDER BY company_no, dept_no
November 22, 2004 at 1:29 pm
Just one minor change to snow.surfer on the select list use:
SELECT IsNull(counts.company_no,'?') as Company_no, depts.dept_no, IsNull(counts.count,0) as Counts FROM ...
HTH
* Noel
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply