[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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

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
Murray Brown
Asked:
Murray Brown
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now