title: SQL: Integer Expected error while casting to decimal from a column
body: <p>This is my SQL and its a snippet from the Select Statement... 
  it is running fine, but now i have to remove the hardcoded values from the CAST ... where i enter the <strong><em>Decimal(38,2)</em></strong>  i want that to be replaced from the <strong><em>BaseCurrencyDP.NumberOfDecimalPlaces</em></strong></p>
  
  <p>But it says Integer expected, and this column <code>NumberofDecimalPlaces</code> in a <code>tinyint</code>.</p>
  
  <p>please guide</p>
  
  <pre><code>select distinct
  a,
  b,
  c,
  
  CASE 
  When @userOriginalCurrencyCode IS NOT NULL -- Case For Original Currency Filled in Criteria .
  Then SUM(CASE WHEN EmployeeHeader.EmployeePremiumType  = 2 THEN EmployeeAmount.TransactionClosedAmountOriginal ELSE 0 END) 
  When @userAccountingCurrencyCode IS NOT NULL
  THEN SUM(CASE WHEN EmployeeHeader.EmployeePremiumType  = 2 THEN EmployeeAmount.TransactionClosedAmountAccounting ELSE 0 END ) 
  ELSE CASE
  
  WHEN (select COUNT( DISTINCT( EmployeeAmountGroup.OriginalCurrencyCode )) from user.EmployeeAmountGroup  Where EmployeeAmountGroup.EmployeeHeaderID = EmployeeHeader.EmployeeHeaderID )&lt;&gt;1
   THEN                      
      CASE WHEN(select COUNT( DISTINCT( EmployeeAmountGroup.AccountingCurrencyCode )) from user.EmployeeAmountGroup  Where EmployeeAmountGroup.EmployeeHeaderID = EmployeeHeader.EmployeeHeaderID)&lt;&gt;1
         THEN       
              CAST(ROUND(SUM(CASE WHEN EmployeeHeader.EmployeePremiumType  = 2 THEN EmployeeAmount.TransactionClosedAmountBase ELSE 0 END ),BaseCurrencyDP.NumberOfDecimalPlaces) AS Decimal(38,2))
         ELSE CAST(ROUND(SUM(CASE WHEN EmployeeHeader.EmployeePremiumType  = 2 THEN EmployeeAmount.TransactionClosedAmountAccounting ELSE 0 END ),BaseCurrencyDP.NumberOfDecimalPlaces) AS Decimal(38,2))
      END                           
   ELSE CAST(ROUND(SUM(CASE WHEN EmployeeHeader.EmployeePremiumType  = 2 THEN EmployeeAmount.TransactionClosedAmountOriginal ELSE 0 END ),BaseCurrencyDP.NumberOfDecimalPlaces) AS Decimal(38,2))
  END
  End as TotalClosedAmount,
  </code></pre>
  
  <p>Please guide </p>