Solved

VB.net SQL show all of one field in aggregate function

Posted on 2014-02-19
2
195 Views
Last Modified: 2014-02-19
Hi
I am using the following SQL statement to get the total Amount for each company.
The result only shows a few companies. I need ll companies to be returned even if the aggregate is null or zero. How do I achieve this? Should I do an outer join on a select that selects just company or is there an easier methos?

SELECT [Company],Sum(Amount) As Aggregate FROM Table_Pivot)  Group By [Company]
0
Comment
Question by:murbro
2 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39869914
you need to start from a table containing all the companies.

select *
from Companies as C
left join (
   SELECT [Company],Sum(Amount) As Aggregate
   FROM Table_Pivot  
   Group By [Company]
) as T
on C.CompanyField = T.Company
0
 

Author Closing Comment

by:murbro
ID: 39869915
Thanks very much
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now