SELECT Distinct a1.projNr ,a1.location ,a1.Amount FROM ( SELECT projNr ,location ,Amount FROM [dbo].Year2009 UNION SELECT projNr ,location ,Amount FROM [dbo].Year2010 ) a1 WHERE a1.projNr = 'A.023'
SELECT a1.projNr ,a1.location ,a1.Amount FROM ( SELECT projNr ,location ,Amount FROM table_2009 UNION ALL SELECT projNr ,location ,Amount FROM table_2010 ) a1 WHERE a1.projNr = 'A.023'
Hi Try this Query
Select tb2.projNr,SUM(tb1.Year2009Amount+tb2.Year2010Amount) as Total,tb2.location from (select projNr,SUM(Amount) as Year2009Amount,location from year2009 group by projNr,location)tb1 inner join (select projNr,SUM(Amount) as Year2010Amount,location from year2010 group by projNr,location)tb2 on tb1.projNr=tb2.projNr group by tb2.projNr,tb2.location
or Use Union All
Select tbl.projNr,tbl.location,Sum(tbl.Amount) as Total from (select * from year2009 union all select * from year2010)tbl group by tbl.projNr,tbl.location
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)