Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
In Line Computation
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01328300
Message ID:
01328337
Views:
6
Kevin,

You can use a subquery within your query to return the calculated amounts, and then use those amounts in your main query...
SELECT 
   t0.NetAmount,
   (t0.decTrade_Product_Balance / t0.decTrade_Qty) * t0.NetAmount AS NotShip
   FROM (SELECT	
            t.decTrade_Ext_Price + t.decTrade_Shipping_Charge + t.decTrade_Other_Charge AS NetAmount,
            t.decTrade_Product_Balance,
            t.decTrade_Qty
      	FROM Trade t
      	JOIN Trading_Partner tp ON tp.iTrading_Partner_ID = t.iTrading_Partner_ID
      	JOIN Product p ON p.sProduct_CD = t.sProduct_CD) t0
Kurt

>Why doesn't this work? I'm trying to first compute NetAmount, then use it in the next column:
>
>
>
>SELECT	t.decTrade_Ext_Price + t.decTrade_Shipping_Charge + t.decTrade_Other_Charge AS NetAmount,
>		(t.decTrade_Product_Balance / t.decTrade_Qty) * NetAmount AS NotShip
>	FROM Trade t
>	JOIN Trading_Partner tp ON tp.iTrading_Partner_ID = t.iTrading_Partner_ID
>	JOIN Product p ON p.sProduct_CD = t.sProduct_CD
>
>
>
>However, this does work with the computation included in the column
>
>
>SELECT	(t.decTrade_Product_Balance / t.decTrade_Qty) * (t.decTrade_Ext_Price + t.decTrade_Shipping_Charge + t.decTrade_Other_Charge) AS NotShip
>	FROM Trade t
>	JOIN Trading_Partner tp ON tp.iTrading_Partner_ID = t.iTrading_Partner_ID
>	JOIN Product p ON p.sProduct_CD = t.sProduct_CD
>
Previous
Reply
Map
View

Click here to load this message in the networking platform