Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 2624 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello

I have 2 tables linked by pk and fk. They are jobs and quotes. A job can have a few versions of a quote, the last one being the most up to date.

I can find the latest related record and return that field, but I want to return the cost of that single related record too.

I have tried using If (latest related record=pk of record ; cost; 0) but it doesn't work. Any help appreciated - I am sure it is pretty simple.

Thanks

W

Posted

Have a look at the Last() function. Note that the order of related records can be changed by sorting the relationship. If you sort the related records by date, descending, the latest record will become the first related record and its fields can be referenced simply by their names (or displayed directly on the layout of the parent table).

  • Like 1
Posted

Thanks. I was trying to overcomplicate things by trying to reference via the last ID to get to the field I wanted. I just use Last(field I wanted) and it did the trick.

Cheers

Posted (edited)

If you wanted to make this independent of any sorting order on your relationship, you could use some SQL to get the value you need. It would look something like this :-

Set Variable ( $lastestCost ; ExecuteSQL ("

SELECT cost

FROM quotes

WHERE fk = ?

SORT BY dateOfQuote DESC

FETCH FIRST 1 ROW ONLY " ; "" ; "" ; pk ) )

The 'DESC' in the SORT BY line means 'descending', so that the matching quotes are sorted newest first, and the FETCH line means you will only return the 'cost' from the most recent quote.

Love a bit of SQL!

Edited by rwoods

This topic is 2624 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.