select summ.Product, summ.LocaleID, summ.Language,@ID as 'KB Number', COUNT(distinct case when ps.LastState=107 or ps.LastState=105 then ps.ResourceID else NULL end) as 'Distribution Successful', COUNT(distinct case when ps.LastState=102 then ps.ResourceID else NULL end) as 'Reboot Pending', COUNT(distinct case when ps.LastState=101 then ps.ResourceID else NULL end) as 'Distribution Failed', COUNT(distinct case when ps.LastState not in (107,105,101,102) then ps.ResourceID else NULL end) as 'Distribution Incomplete', COUNT(distinct ps.ResourceID) as 'In Distribution Scope', ROUND(100.0*COUNT(distinct case when ps.LastState=107 or ps.laststate=102 or ps.laststate=105 then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'Success %', ROUND(100.0*COUNT(distinct case when ps.laststate=101 then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'failed %', ROUND(100.0*COUNT(distinct case when ps.LastState not in (107,105,101,102) then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'Incomplete %' from v_GS_PatchStatusEx ps join v_ApplicableUpdatesSummaryEx summ on ps.UpdateID=summ.UpdateID where ( summ.ID=@ID or summ.QNumbers=@ID or summ.Title=@ID) and summ.Type='Microsoft Update' group by summ.Product, summ.LocaleID, summ.Language order by summ.Product, summ.LocaleID, summ.Language select summ.Product, summ.LocaleID, summ.Language,@ID1 as 'KB Number', COUNT(distinct case when ps.LastState=107 or ps.LastState=105 then ps.ResourceID else NULL end) as 'Distribution Successful', COUNT(distinct case when ps.LastState=102 then ps.ResourceID else NULL end) as 'Reboot Pending', COUNT(distinct case when ps.LastState=101 then ps.ResourceID else NULL end) as 'Distribution Failed', COUNT(distinct case when ps.LastState not in (107,105,101,102) then ps.ResourceID else NULL end) as 'Distribution Incomplete', COUNT(distinct ps.ResourceID) as C093, ROUND(100.0*COUNT(distinct case when ps.LastState=107 or ps.laststate=102 or ps.laststate=105 then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'Success %', ROUND(100.0*COUNT(distinct case when ps.laststate=101 then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'failed %', ROUND(100.0*COUNT(distinct case when ps.LastState not in (107,105,101,102) then ps.ResourceID else NULL end)/count(distinct ps.ResourceID),2) as 'Incomplete %' from v_GS_PatchStatusEx ps join v_ApplicableUpdatesSummaryEx summ on ps.UpdateID=summ.UpdateID where ( summ.ID=@ID1 or summ.QNumbers=@ID1 or summ.Title=@ID1) and summ.Type='Microsoft Update' group by summ.Product, summ.LocaleID, summ.Language order by summ.Product, summ.LocaleID, summ.Language
Promot for ID and ID1: begin if (@__filterwildcard = '') select distinct Title, ID, QNumbers,Type from v_ApplicableUpdatesSummaryEx order by Title else select distinct Title, ID, QNumbers, Type from v_ApplicableUpdatesSummaryEx WHERE Title like @__filterwildcard order by Title end