Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Sybase > UNION all retur...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 2458 of 2506
Post > Topic >>

UNION all return two rows

by Waleed Seada <waleed.seada@[EMAIL PROTECTED] > Apr 30, 2008 at 01:46 AM

Dear All,

I have created two select statments, each produce three lines with
this layout:

1st Select:
 SELECT ID,
         Part#,
         Period,
         Value,
         Dis,
         Amt,
         sum(NetSaleValue) as NetSaleValue,
         sum(NetSaleProfit) as NetSaleProfit,
         0.00  as Dum1,
         0.00  as Dum2
    FROM RegMaster a, Parts b
Where a.ID = 1 and datepart(yy,a.perdio) = 2007 and regCode = '1487'
and
		 a.id = b.id AND a.part# = b.part#
GROUP BY a.id,
         a.regCode,
         a.Period,
         a.Value,
         a.Dis,
         a.Amount

1st Output:
========
ID Part#	Date	 Values		Dis	Amount	NetSValue	NetSProfit	    Dum1	Dum2
1 1487	2007/01/01 85058.16		0.00	85058.16	170116.32	7045370.52    0.00
0.00
1 1487	2007/02/01 94227.31		0.00	94227.31	188454.62	6695362.70    0.00
0.00
1 1487	2007/03/01 107397.87	0.00	107397.87	214795.74	8771624.18
0.00	0.00

------------------------------------------------------------------------------------------------------------------------------------------------------
2nd Select:
 SELECT ID,
         Part#,
         Period,
         Value,
         Dis,
         Amt,
         0.00  as Dum1,
         0.00  as Dum2,
         sum(NetPurchValue) as NetPurchValue,
         sum(NetPurchProfit) as NetPurchProfit
    FROM RegMaster a, Parts b
Where a.ID = 1 and datepart(yy,a.perdio) = 2007 and regCode = '1487'
and
		 a.id = b.id AND a.part# = b.part#
GROUP BY a.id,
         a.regCode,
         a.Period,
         a.Value,
         a.Dis,
         a.Amount

2nd Output:
========
ID Part#	Date	 Values		Dis	Amount	Dumm1	Dumm2	NetPValue	NetPProfit
1 1487	2007/01/01 85058.16		0.00	85058.16	0.00	0.00	170116.32
7045370.52
1 1487	2007/02/01 94227.31		0.00	94227.31	0.00	0.00	188454.62
6695362.70
1 1487	2007/03/01 107397.87	0.00	107397.87	0.00	0.00	214795.74
8771624.18

------------------------------------------------------------------------------------------------------------------------------------------------------

Now I want to combine then together and have aresult of three lines
with the values of NetSaleValue, NetSaleProfit, NetPurchValue,
NetPurchProfit in ONE line ....

How can I acomplish that ...

Thanks and best regards,
Waleed
 




 3 Posts in Topic:
UNION all return two rows
Waleed Seada <waleed.s  2008-04-30 01:46:04 
Re: UNION all return two rows
bret@[EMAIL PROTECTED]   2008-04-30 08:14:22 
Re: UNION all return two rows
Waleed Seada <waleed.s  2008-05-02 06:15:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Wed Jul 9 2:06:14 CDT 2008.