Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Trying to show on single row

Currently looks like
MS18-03-W10 NULL 5526
MS18-03-W10 24249 NULL
Would like
MS18-03-W10 24249 5526


What I have tried:

SQL
Select Distinct p.name
,Case
When i.installed = '1' then count (c.name)
End 
,Case
When i.installed = '0' then count (c.name)
End 
From vRM_Software_Bulletin_Item_ExactType p
left join vPMWindows_ComplianceReportsDrilldown i on i.SoftwareBulletin = p.Guid
left Join vcomputer  c on c.guid = i._ResourceGuid
Where 
i.ReleaseDate > '2017'
AND
i.BulletinState = '1'
and
p.name = 'MS18-03-W10'
group by p.name, i.Installed
Posted
Updated 29-Mar-18 21:34pm
v3

Try this:

SQL
SELECT p.name,
       SUM(CASE WHEN i.installed = '1' THEN 1 ELSE 0 END) AS counter
FROM   vRM_Software_Bulletin_Item_ExactType AS p
LEFT JOIN vPMWindows_ComplianceReportsDrilldown AS i ON i.SoftwareBulletin = p.Guid
LEFT JOIN vcomputer AS c ON c.guid = i._ResourceGuid
WHERE i.ReleaseDate > '2017'
AND   i.BulletinState = '1'
AND   p.name = 'MS18-03-W10'
GROUP BY p.name, i.Installed 


Minor nit - I like to make all the SQL reserved words all-caps so they stand out a little better. I also use "AS" when I'm specifying aliases, because it's just a good habit to get into.

Furthermore, you don't need DISTINCT if you're using GROUP BY.
 
Share this answer
 
v3
Comments
Member 13751304 29-Mar-18 16:49pm    
I need to have on one row
Bulletin Name Installed Not Installed
MS18-03-W10 17952 563
MS18-03-MR7 18563 2056
Close but not quit what I am looking for

I need to have on one row

Bulletin Name 	Installed	Not Installed
MS18-03-W10	17952	        563
MS18-03-MR7	18563	        2056
 
Share this answer
 
SQL
Select Distinct 
        p.name
       ,SUM(Case When i.installed = '1' then 1 End)
           OVER(PARTITION BY p.name ORDER BY p.name) AS [Installed]	
       ,SUM(Case When i.installed = '0' then  1 End)
           OVER(PARTITION BY p.name ORDER BY p.name) AS [Not Installed] 

  From vRM_Software_Bulletin_Item_ExactType p

  left join vPMWindows_ComplianceReportsDrilldown i 
       on i.SoftwareBulletin = p.Guid
  left Join vcomputer c on c.guid = i._ResourceGuid

 Where 

 i.ReleaseDate > '2017'
 AND
 i.BulletinState = '1'
 
Share this answer
 
As mentioned in previous solution, using windowing functions is one possibility and another could be just summing up the values on an outer query. Something like

SQL
SELECT sub1.Name,
       SUM(sub1.Installed),
       SUM(sub1.NotInstalled)
FROM (SELECT p.name,
             CASE WHEN i.installed = '1' THEN COUNT(c.name) END AS Installed,
             CASE WHEN i.installed = '0' THEN COUNT(c.name) END AS NotInstalled
      FROM vRM_Software_Bulletin_Item_ExactType p
      LEFT JOIN vPMWindows_ComplianceReportsDrilldown i ON i.SoftwareBulletin = p.Guid
      LEFT JOIN vcomputer c ON c.guid = i._ResourceGuid
      WHERE i.ReleaseDate > '2017'
      AND i.BulletinState = '1'
      AND p.name = 'MS18-03-W10'
     GROUP BY p.name, i.Installed) AS sub1 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900