title: T-SQL code producing inconsistently erroneous values
body: <p><img src="https://i.stack.imgur.com/TI4a1.png" alt="enter image description here">
  The above picture if a screen cap of the output from a report I've been making using t-SQL tables and views. Each column has two values the first being the current number and then following the forward slash is the difference value for each week. These numbers look great for most of my reports and yet as you can see the Total column seems to have a completely erroneous value for the difference. </p>
  
  <p>This table was created using the following code </p>
  
  <pre><code>SELECT
     ISNULL(a.[LRPR Biospecimen Consent], 'Missing') AS Consent, 
     CONVERT(varchar, a.Oppong) + ' / ' + CONVERT(varchar, a.Oppong - ISNULL(b.Oppong, 0)) AS Oppong,
     CONVERT(varchar, a.Tousimis) + ' / ' + CONVERT(varchar, a.Tousimis - ISNULL(b.Tousimis, 0)) AS Tousimis,
     CONVERT(varchar, a.Willey) + ' / ' + CONVERT(varchar, a.Willey - ISNULL(b.Willey, 0)) AS Willey,
     CONVERT(varchar, a.Anderson) + ' / ' + CONVERT(varchar, a.Anderson - ISNULL(b.Anderson, 0)) AS Anderson, 
     CONVERT(varchar, a.Bacarra) + ' / ' + CONVERT(varchar, a.Bacarra - ISNULL(b.Bacarra, 0)) AS Bacarra,
     CONVERT(varchar, a.McMahon) + ' / ' + CONVERT(varchar, a.McMahon - ISNULL(b.McMahon, 0)) AS McMahon
  FROM
     dbo.vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot a 
  
     LEFT OUTER JOIN dbo.tbl_vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot b 
     ON ...
  </code></pre>
  
  <p>Variants of this code (with just pathnames changed has given accurate total values for the numbers on both sides of the forward slash.I am a novice SQL user and I just can't seem to figure out why this code has stopped working.</p>
  
  <p>Any helpful advice is much appreciated </p>
  
  <p><em>EDIT</em>
  Below is the code used to create the dbo.vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot Total values. </p>
  
  <pre><code> With T as ( SELECT     [LRPR Biospecimen Consent], [Oppong, Bridget A] AS Oppong,    [Tousimis, Eleni] AS Tousimis, [Willey, Shawna] AS Willey, [Anderson, Lyndsay] AS Anderson, 
                    [Bacarra, Minna Manalo] AS Bacarra, [McMahon, Ann] AS McMahon
  FROM         vw_RPT_Ourisman_BiospecimenConsentWithProvider_List c PIVOT (count([Breast Provider]) FOR [Breast Provider] IN ([Oppong, Bridget A], [Tousimis, Eleni], 
                    [Willey, Shawna], [Anderson, Lyndsay], [Bacarra, Minna Manalo], [McMahon, Ann])) piv
  WHERE     [LRPR Biospecimen Consent] IS NOT NULL)
  SELECT     *
   FROM         T
  UNION ALL
  SELECT     'Total', SUM(Oppong), SUM(Tousimis), SUM(Willey), SUM(Anderson), SUM(Bacarra), SUM(McMahon)
  FROM         T
  </code></pre>