What am I missing. I have this set up exactly like another stored procedure (pivot table) only had to change the names and getting Divide by zero error encountered. Please look at the bold area to see what I'm missing:DECLARE @pivot_cols NVARCHAR(MAX); SELECT @pivot_cols = STUFF((SELECT ',SUM(CASE WHEN year_month = ''' + year_month + ''' THEN icnt END) AS [' + year_month + ' icnt]' + ',SUM(CASE WHEN year_month = ''' + year_month + ''' THEN ncnt END) AS [' + year_month + ' ncnt]' + ',SUM(CASE WHEN year_month = ''' + year_month + ''' THEN tcnt END) AS [' + year_month + ' tcnt]' + ',CAST((SUM(CASE WHEN year_month = ''' + year_month + ''' THEN icnt+0.00 END)/ SUM(CASE WHEN year_month = ''' + year_month + ''' THEN tcnt+0.00 END))*100 as decimal(4, 1)) AS [' + year_month + ' pcnt]' FROM (SELECT DISTINCT RIGHT(CONVERT(VARCHAR(9), CAST(dowrdt AS DATETIME), 6), 6), CONVERT(CHAR(7), CAST(dowrdt AS DATETIME), 126) FROM vw_iclaimsTotals) AS T(year_month, sort) ORDER BY sort FOR XML PATH('') ), 1, 1, ''); DECLARE @pivot_query NVARCHAR(MAX); SET @pivot_query = N'SELECT sort, reg, ' + @pivot_cols + N' ,rpt, region, area, dist, doc ' + N' INTO iClaimsPivot ' + N'FROM (SELECT sort, reg, rpt, region, area, dist, doc, icnt, ncnt, tcnt, pcnt, dowrdt, ' + N'RIGHT(CONVERT(VARCHAR(9), CAST(dowrdt AS DATETIME), 6), 6) AS year_month ' + N'FROM vw_iclaimsTotals) AS F ' + N'GROUP BY sort, reg, area, dist, doc, region, rpt ' + N'ORDER BY sort;'; Execute(@pivot_query);