NickSuite
11/01/2023, 6:36 AMSELECT
TransactionLine.Item,
BUILTIN.DF( TransactionLine.Item ) AS ItemID,
MAX( TranDate ) AS LastPurchasedDate,
BUILTIN.DF(Transaction.entity) AS Name
FROM
Transaction
INNER JOIN TransactionLine ON
( TransactionLine.Transaction = Transaction.ID )
WHERE
( Transaction.Type = 'PurchOrd' ) AND
TransactionLine.Item IN (${itemId.toString()})
GROUP BY
TransactionLine.Item,
BUILTIN.DF(Transaction.entity),
BUILTIN.DF( TransactionLine.Item)
I am not that good with the SQL so any help is appreciated.Clay Roper
11/01/2023, 3:38 PMNickSuite
11/01/2023, 3:38 PMNickSuite
11/01/2023, 3:38 PMClay Roper
11/01/2023, 3:38 PMNickSuite
11/01/2023, 3:39 PMClay Roper
11/01/2023, 3:42 PMNickSuite
11/01/2023, 3:45 PMClay Roper
11/01/2023, 6:27 PMNickSuite
11/01/2023, 7:01 PMClay Roper
11/01/2023, 7:05 PMNickSuite
11/01/2023, 7:10 PMClay Roper
11/01/2023, 7:10 PMClay Roper
11/01/2023, 7:11 PMWHERE dr = 1
to see the full ranked list and see if there are two entries with that ranking for that itemNickSuite
11/01/2023, 7:24 PMClay Roper
11/01/2023, 7:46 PMClay Roper
11/01/2023, 7:47 PMDavid B
11/01/2023, 8:34 PMClay Roper
11/01/2023, 8:38 PMDavid B
11/01/2023, 8:42 PMDavid B
11/01/2023, 9:11 PMKEEP(DENSE_RANK/RANK LAST
will still return multiple rows if there are multiple lines with the same (most recent) trandate
.
Currently that query would just hide this away by giving you the max BUILTIN.DF(entity)
ALPHABETICALLY.
To get a truer LastPurchaseDate entity name, I would recommend sorting by trandate
AND transaction.id
. That way if you have two transactions with the same date, you'll get the entity name for the one with the higher (i.e. more recent) internal id.
Like this:
MAX(BUILTIN.DF(Transaction.entity)) KEEP (DENSE_RANK LAST ORDER BY trandate, transaction.id) AS name
NickSuite
11/02/2023, 12:06 PM