title: Arithmetic overflow error converting nvarchar to data type numeric in insert statement
body: <p>I am trying to insert inside test_Master_Product key values (int values) that, actually, are nvarchar(50) from temp#Master_Product. I have tried either with convert, parse and cast. No one of them is working. The reason why I used nvarchar(50) was because in this temp table there were real values, that then have been updated with their key values. Now, I need to convert these values in INT data type because, even if they are nvarchar(50) they are in reality numbers.</p>
  
  <p>Thanks for the support</p>
  
  <pre><code>
  INSERT INTO [dbo].[test_Master_Product]
             ([PNC_KEY]
             ,[MODEL_KEY]
             ,[GPH_PRODUCT_GROUP_KEY]
             ,[PREDECESSOR_KEY]
             ,[SUCCESSOR_KEY]
             ,[PRODUCED_FROM]
             ,[PRODUCED_UNTIL]
             ,[PACKAGE_HEIGHT]
             ,[PACKAGE_WIDTH]
             ,[PACKAGE_DEPTH]
             ,[SHIPPING_VOLUME]
             ,[ACTIVE]
             ,[SUPPLIER_ID]
             ,[PRODUCTION_BASE_MODEL_KEY]
             ,[PRODGROUP_KEY]
             ,[BRAND_KEY]
             ,[PS_STATUS_KEY]
             ,[INTRASTAT_CODE_KEY]
             ,[FUNCTION_KEY]
             ,[CLASS_KEY]
             ,[INSTALLATION_KEY]
             ,[TYPOLOGY_KEY]
             ,[PLATFROM_KEY]
             ,[MASTER_MODEL_KEY]
             ,[BASE_TEMPLATE_MODEL_KEY]
             ,[PROJECT_NAME_KEY]
             ,[INSERT_DATE]
             ,[UPDATE_DATE])
  
  
  SELECT   
         [PNC_KEY]
        ,CAST([MODEL_KEY] AS int)
        ,CAST([GPH_PRODUCT_GROUP_KEY] AS int)
        ,CAST([PREDECESSOR_KEY] AS int)
        ,CAST([SUCCESSOR_KEY] AS int)
        ,[PRODUCED_FROM]
        ,[PRODUCED_UNTIL]
        ,[PACKAGE_HEIGHT]
        ,[PACKAGE_WIDTH]
        ,[PACKAGE_DEPTH]
        ,CAST([SHIPPING_VOLUME]AS decimal(9,6))
        ,CAST([ACTIVE] AS bit)
        ,CAST([SUPPLIER_ID] AS int)
        ,CAST([PRODUCTION_BASE_MODEL_KEY] AS int)  
        ,CAST([PRODGROUP_KEY] AS int)
        ,CAST([BRAND_KEY] AS int)
        ,CAST([PS_STATUS_KEY] AS int)
        ,CAST([INTRASTAT_CODE_KEY] AS int)
        ,CAST([FUNCTION_KEY] AS int)
        ,CAST([CLASS_KEY] AS int)
        ,CAST([INSTALLATION_KEY] AS int)  
        ,CAST([TYPOLOGY_KEY] AS int)    
        ,CAST([PLATFROM_KEY] AS int)   
        ,CAST([MASTER_MODEL_KEY] AS int)
        ,CAST([BASE_TEMPLATE_MODEL_KEY] AS int)   
        ,CAST([PROJECT_NAME_KEY] AS int)
        ,[INSERT_DATE]
        ,[UPDATE_DATE]
  
  FROM [temp#Master_Product]
  
  </code></pre>
  
  <pre><code>Msg 8115, Level 16, State 8, Line 659
  Arithmetic overflow error converting nvarchar to data type numeric.
  The statement has been terminated.
  </code></pre>