Using your example data (thanks!) I put this together.
It should show you the pairings:
SELECT t.RwNum, t.JobParentID, t.JobSource, t.PackageType, t.UpdateType, t.IsAutoPassed, t.IsCanceled, t.IsSkipped, t.Result, t.Fired, t.RuleName, t2.*
FROM @Tab t
LEFT OUTER JOIN @tab t2
ON t.jobParentID = t2.JobParentID
AND t.RwNum <> t2.RwNum
AND (t.JobSource = t2.JobSource OR (NULLIF(t.JobSource ,'') IS NULL AND NULLIF(t2.JobSource ,'') IS NOT NULL) OR (NULLIF(t2.JobSource ,'') IS NULL AND NULLIF(t.JobSource ,'') IS NOT NULL))
AND (t.PackageType = t2.PackageType OR (NULLIF(t.PackageType ,'') IS NULL AND NULLIF(t2.PackageType ,'') IS NOT NULL) OR (NULLIF(t2.PackageType ,'') IS NULL AND NULLIF(t.PackageType ,'') IS NOT NULL))
AND (t.UpdateType = t2.UpdateType OR (NULLIF(t.UpdateType ,'') IS NULL AND NULLIF(t2.UpdateType ,'') IS NOT NULL) OR (NULLIF(t2.UpdateType ,'') IS NULL AND NULLIF(t.UpdateType ,'') IS NOT NULL))
AND (t.IsAutoPassed = t2.IsAutoPassed OR (NULLIF(t.IsAutoPassed ,'') IS NULL AND NULLIF(t2.IsAutoPassed ,'') IS NOT NULL) OR (NULLIF(t2.IsAutoPassed ,'') IS NULL AND NULLIF(t.IsAutoPassed ,'') IS NOT NULL))
AND (t.IsCanceled = t2.IsCanceled OR (NULLIF(t.IsCanceled ,'') IS NULL AND NULLIF(t2.IsCanceled ,'') IS NOT NULL) OR (NULLIF(t2.IsCanceled ,'') IS NULL AND NULLIF(t.IsCanceled ,'') IS NOT NULL))
AND (t.IsSkipped = t2.IsSkipped OR (NULLIF(t.IsSkipped ,'') IS NULL AND NULLIF(t2.IsSkipped ,'') IS NOT NULL) OR (NULLIF(t2.IsSkipped ,'') IS NULL AND NULLIF(t.IsSkipped ,'') IS NOT NULL))
AND (t.result = t2.Result OR (NULLIF(t.Result ,'') IS NULL AND NULLIF(t2.Result ,'') IS NOT NULL) OR (NULLIF(t2.Result ,'') IS NULL AND NULLIF(t.Result ,'') IS NOT NULL))
AND (t.Fired = t2.Fired OR (NULLIF(t.Fired ,'') IS NULL AND NULLIF(t2.Fired ,'') IS NOT NULL) OR (NULLIF(t2.Fired ,'') IS NULL AND NULLIF(t.Fired ,'') IS NOT NULL))
AND (t.RuleName = t2.RuleName OR (NULLIF(t.RuleName ,'') IS NULL AND NULLIF(t2.RuleName ,'') IS NOT NULL) OR (NULLIF(t2.RuleName ,'') IS NULL AND NULLIF(t.RuleName ,'') IS NOT NULL))
ORDER BY 2 DESC ,1 ASC
No comments:
Post a Comment