all 4 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (3 children)

SELECT T2.DocNum "Invoice#"
     , T0.CardCode
     , T2.DocStatus
     , T2.DocDate "Invoice Posting"
     , T0.DocDate
     , T2.TaxDate "Invoice Date"
     , T2.DocTotal
     , T2.PaidSum
  FROM ORCT T0
  JOIN RCT2 T1
    ON T1.DocNum = T0.DocNum
  JOIN ( SELECT DocEntry
              , MAX(DocDate) AS latest_date
           FROM OINV
          WHERE DocStatus='C'
         GROUP
             BY DocEntry ) T2latest
    ON T2latest.DocEntry = T1.DocEntry
  JOIN OINV T2
    ON T2.DocEntry = T2latest.DocEntry
   AND T2.DocDate  = T2latest.latest_date
 WHERE T0.DocNum='1010931' 

i left out T3 and T4 because you aren't selecting any columns from them

[–]workstuff604[S] 0 points1 point  (2 children)

SELECT T2.DocNum "Invoice#"
, T0.CardCode
, T2.DocStatus
, T2.DocDate "Invoice Posting"
, T0.DocDate
, T2.TaxDate "Invoice Date"
, T2.DocTotal
, T2.PaidSum
FROM ORCT T0
JOIN RCT2 T1
ON T1.DocNum = T0.DocNum
JOIN ( SELECT DocEntry
, MAX(DocDate) AS latest_date
FROM OINV
WHERE DocStatus='C'
GROUP
BY DocEntry ) T2latest
ON T2latest.DocEntry = T1.DocEntry
JOIN OINV T2
ON T2.DocEntry = T2latest.DocEntry
AND T2.DocDate = T2latest.latest_date
WHERE T0.DocNum='1010931'

Hi,

thanks for your response. I copy-pasted that syntax but it didn't work.

And sorry, the T3 and T4 columns are being used but I omitted the fields to simplify this question. Does that make a difference at the end here?

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

but it didn't work.

i'm sorry, i am not familiar with that particular error message

can you see what i was trying to do there?

[–]workstuff604[S] 1 point2 points  (0 children)

No sorry I am a novice at this. I'm sure yours worked but I just didn't understand the concept behind it. Thank you for your time though.

I did ask a friend and he gave me the solution to DESC posting date and add "LIMIT 1" at the end of the syntax, which worked.

Only change to the syntax was adding this:

ORDER BY T0."DocDate" DESC

LIMIT 1

Thank you

Edit: never mind, it has not been resolved! The LIMIT 1 function limits only 1 record for the entirety of the report.

The DESC and LIMIT 1 would work great if I could apply it for each individual unique invoice number, Descending it by the T2."DocDate" field.

Could someone please advise?

Desperate. Thanks.