Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is a great forum to exchange knowledge..."

Geography

Where in the world do Tek-Tips members come from?
supportservice (TechnicalUser)
17 May 12 20:37
Hello,
I have this UNION query but need to have the totals summed when the MainAccountDesc is the same.

CODE

SELECT RotocoSummary.AccountCategoryDesc, RotocoSummary.MainAccountDesc, RotocoSummary.MTD, RotocoSummary.LMTD, RotocoSummary.YTD, RotocoSummary.LYTD FROM RotocoSummary LEFT JOIN SB1Summary ON (RotocoSummary.MainAccountDesc = SB1Summary.MainAccountDesc) AND (RotocoSummary.AccountCategoryDesc = SB1Summary.AccountCategoryDesc) UNION SELECT SB1Summary.AccountCategoryDesc, SB1Summary.MainAccountDesc, SB1Summary.MTD, SB1Summary.LMTD, SB1Summary.YTD, SB1Summary.LYTD FROM RotocoSummary LEFT JOIN SB1Summary ON (RotocoSummary.MainAccountDesc = SB1Summary.MainAccountDesc) AND (RotocoSummary.AccountCategoryDesc = SB1Summary.AccountCategoryDesc);

RESULT:

CODE

AccountCategoryDesc MainAccountDesc MTD LMTD YTD LYTD Assets ACCUMULATED DEPRECIATION 0 3316.17 10149.61 13264.68 Assets ACCUMULATED DEPRECIATION 0 21615.27 23158 86461.08

It should be combined not two separate lines.
I'm not sure how to do that?
PHV (MIS)
17 May 12 21:06
Perhaps this ?

CODE

SELECT AccountCategoryDesc,MainAccountDesc,Sum(MTD) AS totMTD,Sum(LMTD) AS totLMTD,Sum(YTD) AS totYTD,Sum(LYTD) AS sLYTD FROM (SELECT AccountCategoryDesc,MainAccountDesc,MTD,LMTD,YTD,LYTD FROM RotocoSummary UNION ALL SELECT AccountCategoryDesc,MainAccountDesc,MTD,LMTD,YTD,LYTD FROM SB1Summary) U GROUP BY AccountCategoryDesc,MainAccountDesc

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close