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 |
|
chaturap
Starting Member
2 Posts |
Posted - 2010-03-24 : 02:19:48
|
| Hi,I need to combine 2 result sets from 2 queries.Output of query 1,package_id incoming---------- --------1 52 44 3Output of query 2,package_id outgoing---------- --------1 23 35 1I need to get the following combine result set,package_id incoming outgoing---------- -------- --------1 5 22 4 3 34 3 5 1I tried this with union, but it is not giving the expected output.Appreciate your comments.Thanks,Chatu |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-24 : 02:24:30
|
[code]select package_id,, incoming = sum(incoming), outgoing = sum(outgoing)from(select package_id, incoming, outgoing = NULLfrom query1union allselect package_id, incoming = NULL, outgoingfrom query2) qgroup by package_id[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
chaturap
Starting Member
2 Posts |
Posted - 2010-03-24 : 03:29:08
|
| Thanks for the quick reply, but it gives an error to union all.BTW, there is no need to calculate the sum.Thing is I have many mobile packages and their incoming rates are in tblincoming table. Their outgoing rates are in a different table called tbloutgoing. I need to just display packeage_id, incoming, outgoing rates in a one result set. Problem is some packages may have only either incoming rate or outgoing rate. As a result combined results set will have null values.Query 1: SELECT package_id, incoming FROM tblincomingQuery 2: SELECT package_id, outgoing FROM tbloutgoingI just need to display package_id, incoming, outgoing columns without duplications in a one result set.Thanks in advance.....BR,Chatu |
 |
|
|
|
|
|
|
|