Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
I have two different table suppose table1 AND table2 here i want to calculate the Total Quantity from both the table (table1 + table2) using sub query & join Like.

What I have tried:

Select Sum((isnull(cast(Quantity as float),0))) from table1 

Select Sum((isnull(cast(Quantity as float),0))) from table2


i am using this two different query for getting the result can you suggest me to single query.
Posted
Updated 17-Mar-17 2:36am
Comments
Member 11137292 17-Mar-17 8:37am    
Do you mean something like this?

Select Sum(TableTotal) AS GrandTotal
FROM (
Select Sum((isnull(cast(Quantity as float),0))) AS TableTotal from dbo.table1
UNION ALL
Select Sum((isnull(cast(Quantity as float),0))) AS TableTotal from dbo.table2
) AS SourceData

1 solution

Adapt from this
select (select Sum(isnull(cast(Quantity as float),0)) from table1) + (select Sum(isnull(cast(Quantity as float),0)) from table2)
 
Share this answer
 
Comments
AZHAR SAYYAD 17-Mar-17 10:02am    
CAN WE GROUP BY USING THE id COLUMN IN THIS QUARY

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