title: Divided by zero encountered in SQL
body: <p>So, I have a query where I am able to get some values using some formulas and that kind of stuff. When the query have values it will work fine, but if I have no values, in the divided formulas it will give me the know error</p>
  
  <blockquote>
    <p>Divided by zero encountered</p>
  </blockquote>
  
  <p>This is the query: </p>
  
  <pre><code>WITH TrashFile AS(
  SELECT FileType AS[Extension],
  COUNT(*) AS [Nº of files],
  CAST(((COUNT(FileSize) * 100.0) / (SELECT COUNT(*) FROM InfoFile))
  AS DECIMAL(10, 2)) AS[Percentage(%)],
  CAST((SUM(FileSize) / 1024.0) AS DECIMAL(10,1)) AS [Total(KB)],
  NULL AS [Converted to MB],
  NULL AS [Converted to GB],
  MIN(COUNT(*)) OVER() * 100.0 / (SUM(COUNT(*)) OVER()) AS[Min.Percentage(%)],
  MAX(COUNT(*)) OVER() * 100.0 / SUM(COUNT(*)) OVER() AS[Max.Percentage(%)]
  FROM InfoFile
  GROUP BY FileType)
  SELECT[Extension],
  [Nº of files],
  [Percentage(%)],
  [Total(KB)],
  [Converted to MB],
  [Converted to GB],
  NULL AS[Min.Percentage(%)],
  NULL AS[Max.Percentage(%)]
  FROM TrashFile
  UNION ALL
  SELECT '-----------------------------',
  COUNT('Nº de extensions'),
  ((COUNT(FileType) * 100) / (SELECT COUNT(FileType) FROM InfoFile)),
  CAST((SUM(FileType) / 1024.0) AS DECIMAL(10,1)),
  CAST((SUM(FileType) / 1024.0 / 1024.0) AS DECIMAL(10,5)),
  CAST((SUM(FileType) / 1024.0 / 1024.0 / 1024.0) AS DECIMAL(10,9)),
  CAST(((SELECT MAX([Min.Percentage(%)]) FROM TrashFile)) 
  AS DECIMAL(10,2)) AS[Min.Percentage(%)] ,
  CAST((SELECT MAX([Max.Percentage(%)]) FROM TrashFile) 
  AS DECIMAL(10,2)) AS[Max.Percentage(%)]
  FROM InfoFile
  </code></pre>
  
  <p>Do you have any idea how I can solve it?</p>