Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert R&R Report Sum To SQL
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01327748
Message ID:
01327750
Vues:
10
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform