Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
andypgill
Starting Member
34 Posts |
Posted - 2013-08-28 : 17:09:11
|
HiI have two queries in SQL linked to excel.Report 1 showsContract A E N PIncome 5000 6000 8000 4000Costs 4000 7000 6000 3000Report2 shows Contract A B ECustomerA 500 200 400CustomerB 450 100 200Is it possible to combine them so I getContract A B E N PIncome 5000 6000 8000 4000Costs 4000 7000 6000 3000CustomerA 500 200 400CustomerB 450 100 200ThanksSent from my iPad |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-08-28 : 17:20:58
|
Can you try using a UNION like shown below:SELECT contract, A, NULL AS B, E, N, P FROM Report1TableUNION ALLSELECT contract, A, B, E, NULL, NULL FROM Report2Table If you have specific ordering needs that would need to be added in. |
|
|
andypgill
Starting Member
34 Posts |
Posted - 2013-08-29 : 02:48:16
|
quote: Originally posted by James K Can you try using a UNION like shown below:SELECT contract, A, NULL AS B, E, N, P FROM Report1TableUNION ALLSELECT contract, A, B, E, NULL, NULL FROM Report2Table If you have specific ordering needs that would need to be added in.
HiThanks for the reply, however to do that wouldn't I need to know all the data (of which in reality there is lots) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-08-29 : 03:16:18
|
quote: Originally posted by andypgill
quote: Originally posted by James K Can you try using a UNION like shown below:SELECT contract, A, NULL AS B, E, N, P FROM Report1TableUNION ALLSELECT contract, A, B, E, NULL, NULL FROM Report2Table If you have specific ordering needs that would need to be added in.
HiThanks for the reply, however to do that wouldn't I need to know all the data (of which in reality there is lots)
You need to know only about columns involved not on actual data. also all tables should have equal number of columns with corresponding types equal.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-08-29 : 05:13:07
|
SELECT Contract,A,Null AS 'B',E,N,P FROM ReportTable1UNION allSELECT Contract,A,B,E,Null AS 'N',Null AS 'P' FROM ReportTable2veeranjaneyulu |
|
|
|
|
|
|
|