SQL COUNT Rows Result in separate columns

Viewed 3653

I currently use this to count all the number or rows in a table and it works well for what i need.

SELECT COUNT(*) AS STCount 
  FROM  (SELECT Distinct DPoint, RNum 
           FROM ECount  
          WHERE DType = 'STR' AND Month(EDate) = '07') AS rows

The only issue i have is i have to repeat this statement a lot while just changing a few things each time. I would like to Union these Selects but have the result show in a seperate column, the example below works getting the results but puts them all in the same column. Any ideas how to have them show in their own column one for STCount and NCCount?

SELECT COUNT(*) AS STCount 
  FROM (SELECT Distinct DPoint, RNum 
          FROM ECount  
         WHERE DType = 'STR' AND Month(EDate) = '07') AS rows 
 UNION 
SELECT COUNT(*) AS NCCount 
  FROM (SELECT Distinct DPoint, RNum 
          FROM ECount  
         WHERE DType = 'NCD' AND Month(EDate) = '07') AS rows

result would be,

STCount NCCount
  100     202
7 Answers
Related