Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert R&R Report Sum To SQL
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01327748
Message ID:
01327750
Views:
9
The question is a bit unclear (how do you calculate this SUM field), but you can add a derived table to your INNER JOINs, e.g.
inner join (select custID, sum(myField) as Summary group by 1) SumInfo on myMainTable.custID = SumInfo.custID
>I have an R&R report field called 'CUSMV' which is being summed into a report field called 'MVTOT'. The value is reset each time the CustNum field changes.
>
>So far my query is
>
>SELECT
>	t.dtTrade_DT,
>	t.iOrder_Hdr_ID,
>	t.iTrade_ID,
>	t.sTrade_Type_CD,
>	t.sProduct_CD,
>	t.decTrade_Qty,
>	t.decTrade_Unit_Price,
>	t.decTrade_Qty * t.decTrade_Unit_Price AS Net_Amount,
>	t.decTrade_Cash_Balance,
>	t.decTrade_Product_Balance,
>	t.iTrade_Conf_No,
>	tp.sTP_Name1,
>	tp.iTrading_Partner_ID,
>	CASE
>		WHEN p.sCommodity_CD = 'G'  THEN t.decTrade_Cash_Balance * p.decProduct_Ozconv
>		ELSE 0
>	END AS goz,
>		CASE
>		WHEN p.sCommodity_CD = 'S'  THEN t.decTrade_Cash_Balance * p.decProduct_Ozconv
>		ELSE 0
>	END AS soz,
>	CASE
>		WHEN p.sCommodity_CD = 'P'  THEN t.decTrade_Cash_Balance * p.decProduct_Ozconv
>		ELSE 0
>	END AS poz,
>	CASE
>		WHEN p.sCommodity_CD = 'L'  THEN t.decTrade_Cash_Balance * p.decProduct_Ozconv
>		ELSE 0
>	END AS loz,
>	t.decTrade_Product_Balance * p.decProduct_Ozconv * c.decSpot_Price AS cusmv
>	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
>	JOIN Commodity c ON c.sCommodity_CD = p.sCommodity_CD
>
>
>
>
>How do I add this sum field to this query?
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform