Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello-

I have 4 SQL Server database servers that 'should' store all the same data. They are there for redundancy. Over time, some SQL Server Agent Jobs get added to one server and not the others. The discrepancies build up slowly over time. I am just looking to compare job names across the 4 different servers. I used a FULL OUTER JOIN to include all jobs but the jobs on server B, C and D do not 'line-up' in the query results. The first server (Server A) lines up everything perfectly but if a job doesn't exist on Server A but does on the other 3, the results do not line up for easier reference. I'm not sure how else to do this.

Below are the results I'm getting but do no want. Report 1, 2 and 3 line up great. Report 4 and 5 exists on servers B, C and D but not A. But reports 4 and 5 should be on the same line, except for Server A obviously. Thank you !


SERVER_A	SERVER_B	SERVER_C	SERVER_D
REPORT_1	REPORT_1	REPORT_1	REPORT_1
REPORT_2	REPORT_2	REPORT_2	REPORT_2
REPORT_3	REPORT_3	REPORT_3	REPORT_3
NULL	    REPORT_4	NULL	    NULL
NULL	    REPORT_5	NULL	    NULL
NULL	    NULL	    REPORT_4	NULL
NULL	    NULL	    REPORT_5    NULL
NULL	    NULL	    NULL	    REPORT_4
NULL	    NULL	    NULL	    REPORT_5


What I have tried:

SELECT A.name, B.name, C.name, D.name
FROM A.msdb.dbo.sysjobs A
FULL JOIN B.msdb.dbo.sysjobs B
ON A.name = B.name 
FULL JOIN C.msdb.dbo.sysjobs C
ON A.name = C.name 
FULL JOIN D.msdb.dbo.sysjobs D
ON A.name = D.name 
Posted
Updated 7-Nov-22 22:02pm

1 solution

Your joins all depend on A.name, which will be null if the job doesn't exist on server A.

Try something like this:
SQL
SELECT A.name, B.name, C.name, D.name
FROM A.msdb.dbo.sysjobs A
FULL JOIN B.msdb.dbo.sysjobs B ON B.name = A.name
FULL JOIN C.msdb.dbo.sysjobs C ON C.name = Coalesce(A.name, B.name)
FULL JOIN D.msdb.dbo.sysjobs D ON D.name = Coalesce(A.name, B.name, C.name)
 
Share this answer
 
Comments
Chris_List 8-Nov-22 23:51pm    
Thank you !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900