cancel
Showing results for 
Search instead for 
Did you mean: 

Query with GROUP BY function

Former Member
0 Kudos

Hi all,

I have the following query:

SELECT T0.[CardCode], T0.[CardName], T1.[ItemCode], T1.[Dscription], T1.[Quantity], T1.[LineTotal] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[CardCode] >=[%0] and T0.[CardCode] <=[%1] and T0.[DocDate] >=[%2] and T0.[DocDate] <=[%3]

GROUP BY T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity, T1.LineTotal

Currently it is returning something along the lines:

#Customer/Supplier CodeCustomer/Supplier NameItem No.Item/Service DescriptionQuantityRow Total
1C20000Norm ThompsonA00001IBM Infoprint 13121300
2C20000Norm ThompsonA00001IBM Infoprint 131211,500.00
3C20000Norm ThompsonA00001IBM Infoprint 131251,500.00
4C20000Norm ThompsonA00001IBM Infoprint 1312103,000.00
5C20000Norm ThompsonA00001IBM Infoprint 1312206,000.00
6C20000Norm ThompsonA00001IBM Infoprint 1312257,500.00
7C20000Norm ThompsonA00001IBM Infoprint 1312309,000.00

Where as I want it to return something along the lines of:

#Customer/Supplier CodeCustomer/Supplier NameItem No.Item/Service DescriptionQuantityRow Total
1C20000Norm ThompsonA00001IBM Infoprint 13129228800

I want it to be grouped by Item code, quantity and line total.  Can someone please help on this one please?

Have tried to group this together and take out card code and/or card name but will not allow and wont return what I am looking for.

Thanks very much,

Brian

Accepted Solutions (1)

Accepted Solutions (1)

former_member217514
Active Contributor
0 Kudos

SELECT T0.[CardCode], T0.[CardName], T1.[ItemCode], T1.[Dscription], SUM(T1.[Quantity]), SUM(T1.LineTotal)

FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[CardCode] >=[%0] and T0.[CardCode] <=[%1] and T0.[DocDate] >=[%2] and T0.[DocDate] <=[%3]

GROUP BY T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription

Former Member
0 Kudos

Thanks Jitin and Jeff

Answers (1)

Answers (1)

jitin_chawla
Advisor
Advisor
0 Kudos

Hi,

Check this :

SELECT T0.[CardCode], T0.[CardName], T1.[ItemCode], T1.[Dscription], sum(T1.[Quantity]),

sum(T1.[LineTotal])

FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[CardCode] >=[%0] and T0.[CardCode] <=[%1] and T0.[DocDate] >=[%2] and T0.[DocDate] <=[%3]

GROUP BY T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription

Kind Regards,

Jitin

SAP Business One Forum Team