cancel
Showing results for 
Search instead for 
Did you mean: 

Return max value of numeric field

Former Member
0 Kudos

Post Author: misslora

CA Forum: Formula

Database field is character. Converted to numeric via formula.

Would like to select only those records with the max value for the numeric field.

Two tables: Customer and payment tables

Customer table has customer ID and and order ID. Payment table has customer ID and payment id. The customer has only only customer id but could have multiple order ID's that are used to link the customer back to the Order table.

When running a report for customer payments, I get multiple rows for the same payment when the customer has multiple order ID's. I'd like the report to resolve the duplicate by assessing the max order ID and returning only the one payment.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Post Author: Lugh

CA Forum: Formula

The simplest solution is to do this in your SQL query:SELECT Pay.CustomerID, Order.OrderID, Pay.PaymentIDFROM PayLEFT JOIN OrderON Pay.CustomerID = Order.CustomerIDWHERE Order.OrderID IN (SELECT Max(OrderID) FROM Order WHERE Order.CustomerID = Pay.CustomerID) If you can't manipulate the SQL, there is another option. Group the records by the CustomerID of the Payment table. Set up a formula to suppress the details section if <> Maximum (,)