Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Getting the counts and comparing with the inventory table

$
0
0

Hello All,

I have table called data inventory which has 3 columns, ID, TableName and AvailableRecords.

ID                 TableName                AvailableRecords

1                   ABC                               20

1                   DEF                               25

1                   GHC                               30

I also have individual tables Incident_ABC, Incident_DEF, Incident_GHC. In the inventory table we dont have Incident_ prefix in the tablename's data. The common column between the incident tables and the inventory table is the ID. I need to write a script to get the below columns,

ID                      TableName                  AvailableRecvords_Inventory                     TotalRecs_Incident

1                        ABC                                      20                                                               20

1                         DEF                                     25                                                               25

TotalRecs_Incident is the no. of records in each specific incident table. For the first record, for tablename ABC, TotalRecs_Incident should be total number of records in Incident_ABC. This script we will use to validate the counts what we have in inventory and the incident tables for a specific ID. Please help me in achieving this. Really appreciate any kind of help.

Thanks so much.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>