Question

I have different temptables with Branch Names in - I want to do a do count of the Branch Names from each table.
My temptables are #CAT1, #CAT2, #CAT3, #CAT4 and they each look like this:

Branch_Name      Friday    Saturday    Sunday 
BranchA        57        53        54  
BranchB        51        23        22  

I would like a total of all Branch_Name from each temptable (there are no duplicates). Is this possible?

I've tried this, but I think I should be joining maybe?

select COUNT(*)Branch_Name  
into #BranchCount  
from #CAT1, #CAT2, #CAT3, #CAT4
Was it helpful?

Solution

How about using a UNION ALL

Something like

select COUNT(*)Branch_Name
FROM    (
            SELECT  *
            FROM    #CAT1
            UNION ALL
            SELECT  *
            FROM    #CAT2
            SELECT  *
            FROM    #CAT3
            SELECT  *
            FROM    #CAT4
        ) t
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top