Skip to Content
author's profile photo Former Member
Former Member

Query Help ! Showed duplicate records

Hi,

Below is the query that will showed duplicate records.

Can anyone please help to refined the query?

"DISTINCT" will not work, as document may include same item in different row. It will eliminate the correct records if apply "DISTINCT" to query.

SELECT T0.[DocDate], T0.[DocNum], T0.[CardName], T0.[CardCode], T1.[ItemCode], T1.[Quantity], T1.[Currency], T1.[PriceBefDi], T1.[LineTotal],T1.[TotalFrgn], T1.[StockPrice], T2.[AvgPrice], T3.[ItmsGrpNam], T2.[U_PROD_GROUP], T4.[Number], T0.[DocRate], T6.[DocNum] FROM ODLN T0 INNER JOIN DLN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB T3 ON T2.ItmsGrpCod = T3.ItmsGrpCod INNER JOIN OJDT T4 ON T0.TransId = T4.TransId JOIN INV1 T5 ON T1.DocEntry = T5.BaseEntry JOIN OINV T6 ON T5.DocEntry = T6.DocEntry

Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2015 at 04:08 PM

    try this...

    SELECT T0.[DocDate], T0.[DocNum], T0.[CardName], T0.[CardCode], T1.[ItemCode], T1.[Quantity], T1.[Currency], T1.[PriceBefDi], T1.[LineTotal],T1.[TotalFrgn], T1.[StockPrice], T2.[AvgPrice], T3.[ItmsGrpNam], T2.[U_PROD_GROUP], T4.[Number], T0.[DocRate], T6.[DocNum] FROM ODLN T0 INNER JOIN DLN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB T3 ON T2.ItmsGrpCod = T3.ItmsGrpCod INNER JOIN OJDT T4 ON T0.TransId = T4.TransId JOIN INV1 T5 ON T1.DocEntry = T5.BaseEntry and T1.linenum=T5.baseline JOIN OINV T6 ON T5.DocEntry = T6.DocEntry

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2015 at 03:41 AM

    What result you want from this query?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,


      Currently the document records as below:

      PART | QTY

      A001 | 10

      A002 | 20

      A001 | 5

      Expected result as below:

      A001 | 10

      A002 | 20

      A001 | 5

      The filed that needed.

      ODLN.DocDate, ODLN.DocNum, ODLN.CardName, ODLN.CardCode, DLN1.ItemCode, DLN1.Quantity, DLN1.Currency, DLN1.PriceBefDi, DLN1.LineTotal, DLN1.StockPrice, OITM.AvgPrice, OITB.ItmsGrpNam, OITM.U_PROD_GROUP, OJDT.Number, ODLN.DocRate, OINV.DocNum

      Basically field from ODLN, DLN1, OITM, OITB, OJDT, OINV

      However the result with current query

      A001 | 10

      A001 | 10

      A001 | 10

      A001 | 10

      A002 | 20

      A002 | 20

      A002 | 20

      A002 | 20

      A001 | 5

      A001 | 5

      A001 | 5

      A001 | 5

      Each records will duplicate 4 times, I run the query in crystal report

      Thanks

  • Posted on Dec 08, 2015 at 04:32 AM

    Try This

    SELECT T0.[DocDate], T0.[DocNum], T0.[CardName], T0.[CardCode], T1.[ItemCode], sum(T1.[Quantity]), T1.[Currency], T1.[PriceBefDi],

    T1.[LineTotal],T1.[TotalFrgn], T1.[StockPrice], T2.[AvgPrice], T3.[ItmsGrpNam],OITM.U_PROD_GROUP, T4.[Number], T0.[DocRate], T6.[DocNum]

    FROM ODLN T0 INNER JOIN DLN1 T1

    ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2

    ON T1.ItemCode = T2.ItemCode INNER JOIN OITB T3

    ON T2.ItmsGrpCod = T3.ItmsGrpCod INNER JOIN OJDT T4

    ON T0.TransId = T4.TransId JOIN INV1 T5

    ON T1.DocEntry = T5.BaseEntry JOIN OINV T6

    ON T5.DocEntry = T6.DocEntry

    group by T0.[DocDate], T0.[DocNum], T0.[CardName], T0.[CardCode], T1.[ItemCode], T1.[PriceBefDi],

    T1.[LineTotal],T1.[TotalFrgn], T1.[StockPrice], T2.[AvgPrice], T3.[ItmsGrpNam], T4.[Number], T0.[DocRate], T6.[DocNum],T1.[Currency],OITM.U_PROD_GROUP

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2015 at 05:11 AM

    Hi Hu,

    Please try the below query ......................

    SELECT distinct T0.[DocDate] as 'Del Date', T0.[DocNum] as 'Del No', T0.[CardName], T0.[CardCode], T1.[ItemCode], sum(T1.[Quantity]) as 'Del QTY', T1.[Currency], T1.[PriceBefDi],

    sum(T1.[LineTotal]),sum(T1.[TotalFrgn]), T1.[StockPrice], T2.[AvgPrice], T3.[ItmsGrpNam], T4.[Number], T0.[DocRate]

    FROM ODLN T0 INNER JOIN DLN1 T1 ON T0.[DocEntry] = T1.[DocEntry]

    INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]

    INNER JOIN OITB T3 ON T2.[ItmsGrpCod] = T3.[ItmsGrpCod]

    INNER JOIN OJDT T4 ON T0.[TransId] = T4.[TransId]

    INNER JOIN INV1 T5 ON T2.[ItemCode] = T5.[ItemCode]

    INNER JOIN OINV T6 ON T5.[DocEntry] = T6.[DocEntry]

    group by T0.[DocDate], T0.[DocNum], T0.[CardName], T0.[CardCode], T1.[ItemCode],T1.[Currency], T1.[PriceBefDi], T1.[StockPrice],

    T2.[AvgPrice], T3.[ItmsGrpNam], T4.[Number], T0.[DocRate]

    Rgds,

    Kamlesh Naware

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.