Close Voter Count

0

Please login or register to vote for this query.

(click on this box to dismiss)

Software Engineering

Q&A for expert programmers interested in professional discussions on software development

SELECT Count(ID) kount,
        CASE WHEN GROUPING(CloseCount) = 1 THEN 'ALL'
        ELSE  CAST(CloseCount as varchar(10))
        END [Open Count]
FROM (
  SELECT 
         ph.ID,
         COUNT(t.VALUE) CloseCount
         
         
    FROM
           PostHistory ph
            OUTER APPLY
               ( SELECT 
                  SUBSTRING(',' + text + ',', Number + 1,
                  CHARINDEX(',', ',' + text + ',', Number + 1) - Number -1)AS VALUE
                  FROM master..spt_values 
                  WHERE  Type = 'P'
                     AND Number <= LEN(',' + text + ',') - 1
                     AND SUBSTRING(',' + text + ',', Number, 1) = ','
                     AND ph.postHistoryTypeID =10) t
    WHERE 
         ph.postHistoryTypeID =10  AND  
         (t.value like '"DisplayName":%' or t.value is null)
    GROUP BY 
    ph.Id) data
GROUP BY
      CloseCount WITH ROLLUP
ORDER BY 
CASE WHEN GROUPING(CloseCount) = 1 then 1 else 0 END ,
  CloseCount

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results