title: Error converting data type varchar to numeric from my application
body: <p>Hi i have created a view to calculate the sum col1/ sum col2
  however col1 contains predefined values 100,150,45,50,60 and NA. col1's data type is varchar and col2's data type is numeric. I have set a condition on my statement not to perform any calculation if col1 has a value of 'NA' however i keep getting this error from the application side "error converting data type to numeric"</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>IF EXISTS(SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'ROM_PAD_REPORT') AND XTYPE = 'V')
  DROP VIEW ROM_PAD_REPORT
  GO
  
  CREATE VIEW [dbo].[ROM_PAD_REPORT]  
  AS  
  
  
  
  SELECT  DISTINCT CAST(NULL AS UNIQUEIDENTIFIER) AS PK,
          DTS.PK AS PPK,
    A.PROD_BLOCK,        
          A.ELEVATION,
          A.MATERIAL_TYPE,
       A.SAMPLE_COUNT,
       A.QC_SAMPLE_COUNT,
    A.TRUCK_CAPACITY,
    A.CONTENT,
    A.Valuegt AS GRAMS_PER_BLOCK,
    A.DATE_DISPACTHED as DATE_DISPATCHED         
    
  FROM ( SELECT  RP.PROD_BLOCK,
       MIN(RP.ELEVATION) AS ELEVATION,
       MAX(RP.MATERIAL_TYPE)AS MATERIAL_TYPE,
       MAX(RP.DATE_DISPACTHED) AS DATE_DISPACTHED,
       SUM(CAST (RP.TRUCK_CAPACITY AS varchar(8))) AS TRUCK_CAPACITY,
       SUM(RP.CONTENT) AS CONTENT,  
       (SUM(CAST(RP.TRUCK_CAPACITY AS varchar(8)))/SUM(RP.CONTENT)) AS Valuegt,
       (SELECT COUNT(DD.SAMPLE_ID) FROM ROM_PAD_DATA DD WHERE DD.PROD_BLOCK = RP.PROD_BLOCK) AS SAMPLE_COUNT,
       (SELECT COUNT(DD.SAMPLE_ID) FROM ROM_PAD_DATA DD WHERE DD.PROD_BLOCK = RP.PROD_BLOCK and DD.SAMPLE_TYPE IN ('STD', 'BLANK')) AS QC_SAMPLE_COUNT
    FROM  ROM_PAD_DATA RP 
    WHERE RP.TRUCK_CAPACITY &lt;&gt; 'NA'
    GROUP BY RP.PROD_BLOCK) A
    
  JOIN ROM_PAD_DATA B ON A.PROD_BLOCK = B.PROD_BLOCK
  JOIN DATASET DTS ON (B.PPK = DTS.PK) 
  JOIN BUS_UNIT BU ON (BU.PK = DTS.PPK)
  
  GO
  GRANT SELECT ON ROM_PAD_REPORT TO sableApp
  GO</code></pre>
  </div>
  </div>
  </p>