title: How do I use the Case Expression in conjunction with a where clause to divide one filed by another?
body: <p>I am trying to figure out how to use case expression with a select query and a where clause and alias result as 'CaseOnOrder'.<br>
  Ideally when salunitmsr. = w then divide by U_SpecWgt as Case on order, when salunitmsr. = E than CaseOnOrder = OnOrder</p>
  
  <p>I have two values that can only equal E or W, When the value is 'W' I would like the field OnOrder to divide by the U_SpecWgt field.  When the Value is 'E' than the OnOrder qty will not need to be changed.  The two select queries are below.  I am not sure how to incorporate the case logic to divide when W is present, and keep the value the same when 'E' is present. </p>
  
  <pre><code>SELECT  [ItemCode]
        ,[ItemName]
        ,[FrgnName]
        ,[ItmsGrpCod]
        ,[OnOrder]
        ,[U_SpecWgt]
    FROM [xxxxx].[xxxxx].[xxxxx]
    where 
    SalUnitMsr = 'e'
    AND SellItem = 'Y'
    and OnOrder &gt; 0
  
    SELECT  [ItemCode]
        ,[ItemName]
        ,[FrgnName]
        ,[ItmsGrpCod]
        ,[OnOrder]
        ,[U_SpecWgt]
    FROM [xxxxx].[xxxxx].[xxxxx]
    where 
    SalUnitMsr = 'w'
    AND SellItem = 'Y'
    and OnOrder &gt; 0
  </code></pre>
  
  <p>The query will include an aliased column that divides OnOrder by U_SpecWGT when salunitmsr = W, as cases on order, when E OnOrder = Cases on order.</p>