asp.net - How to get the value from 4 tables -
i want generate report 4 tables.could not figure out how it. using sql server 2008 r2 , asp.net frontend.
[table 1] ---> 2014
----------------------------- division totalprograms ----------------------------- edd-coa 3 edd-edsd 2 edd-eoa 6 edd-soa 2 edd-woa 3
table2 ----> 2013
------------------------------ division totalprograms ------------------------------ edd-coa 24 edd-edsd 3 edd-eoa 14 edd-soa 7 edd-woa 11
table3 ----> 2012
------------------------------ division totalprograms ------------------------------ edd-coa 12 edd-edsd 1 edd-eoa 9 edd-soa 7 edd-woa 12
table4 ---> 2011 (note : edd-soa not present in table)
------------------------------- division totalprograms ------------------------------- edd-coa 2 edd-edsd 1 edd-eoa 3 edd-woa 3
final result should : >>---->
--------------------------------------------- division 2014 2013 2012 2011 --------------------------------------------- edd-coa 3 24 12 2 edd-edsd 2 3 1 1 edd-eoa 6 14 9 3 edd-soa 2 7 7 0 edd-woa 3 11 12 3
but want value edd-soa row in final table m missing .please guide me..
select a.division 'division', (case when a.totalprograms null '0' else a.totalprograms end) '2014', (case when b.totalprograms null '0' else b.totalprograms end) '2013', (case when c.totalprograms null '0' else c.totalprograms end) '2012', (case when d.totalprograms null '0' else d.totalprograms end) '2011' table1 full join table2 b on a.division = b.division full join table3 c on a.division = c.division , b.division = c.division full join table4 d on a.division = d.division , b.division = d.division , c.division = d.division
output:
division 2014 2013 2012 2011 edd-coa 3 24 12 2 edd-edsd 2 3 1 1 edd-eoa 6 14 9 3 edd-soa 2 7 7 0 edd-woa 3 11 12 3
Comments
Post a Comment