Options

Select "newest" date from table

michalkmichalk Member Posts: 43
Hi there - is someone able to tell me, how to select most recent date entry from table?
Ie:
1 2010-01-01
2 2010-04-05
3 2010-02-01

Query should return 2010-01-01

Good example is table 7002 Sales Price where prices for customers are stored - there can be few record per every item number with few dates.

M

Comments

  • Options
    thankeshthankesh Member Posts: 170
    Use FINDFIRST function to get the recently hit value in the table.
    With warm regards,

    Thankesh

    ***Learn to lead***
  • Options
    michalkmichalk Member Posts: 43
    thankesh wrote:
    Use FINDFIRST function to get the recently hit value in the table.

    Going to try it now :)

    And how to check, if given date is in data range?
    Ie: given date 2010-02-01, range 2010-01-20..2010-02-02, returns TRUE

    MK
  • Options
    thankeshthankesh Member Posts: 170
    I do not get you what you are coming to say. Pl be little bit brief in your post. Anyways for checking the range of records use relational operators (<,>,= and so on)
    With warm regards,

    Thankesh

    ***Learn to lead***
  • Options
    mabl4367mabl4367 Member Posts: 143
    Before using FINDFIRST be sure to set the correct key and sort order using SETCURRENTKEY and ASCENDING(FALSE). If there is no key that sorts primarily on the date you are interested in you will have to create one.

    To check if a date is in a certain range use:
    IF (myDate>=myMinDate) AND (myDate>=myMaxDate) THEN
    doSomething();

    If you are only interested in records that are in this range, use SETRANGE(dateField,myMinDate,myMaxDate) before the call to FINDFIRST.
Sign In or Register to comment.