Wednesday, July 2, 2014

Getting the counts and comparing with the inventory table

I think what you can do is this



SELECT inv.ID,
inv.TableName,
inv.AvailableRecords AS AvailableRecords_Inventory,
inc.Cnt AS TotalRecs_Incident
FROM DataInventory inv
LEFT JOIN (SELECT ID,'ABC' AS TableName,COUNT(*) AS Cnt
FROM Incident_ABC
UNION ALL
SELECT ID,'DEF' AS TableName,COUNT(*)
FROM Incident_DEF
UNION ALL
SELECT ID,'GHC' AS TableName,COUNT(*)
FROM Incident_GHC
)inc
ON inc.ID = inv.ID
AND inc.TableName = inv.TableName





Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c


No comments:

Post a Comment