I’m trying to output some data in MSSQL from 3 different tables (status, status & cases) in 2 different databases (global & private).
global.status // contains labels for global status ID's
fields (id, text)
private.status // contains labels for private status ID's
fields (id, text)
private.cases // contain case information, such as status
fields (status, count(status) AS amount)
I need to compare the status in the cases table with the status ID in the two status tables and output the following:
statusID | text | amount
----------|-------------|--------
9993 | Open | 24
9991 | Closed | 3
9992 | Pending | 12
The reson for having global and private is that private allows custom private status where global is accessible throughout the system.
My unsuccessful attempt with this was the following sql
SELECT c.status,
COUNT(c.status) as amount,
ss.text,
gs.text
FROM [DB11111111].dbo].[cases] AS c, [DB11111111].[dbo].[status] AS ss, [global].[dbo].[status] AS gs
WHERE (c.status = ss.id) OR (c.status = gs.id)
GROUP BY c.status, ss.text, gs.text
ORDER BY amount DESC
Do you have any idea what to do??
You might union/union all local and global statuses if they are distinct:
If they overlap, you need to define which one takes precedence and use full outer join on them.