Function to fetch minimum date

mkpjsr
Member Posts: 587
Hi all,
can anybody tell me a function to fetch minimum date from a table.
can anybody tell me a function to fetch minimum date from a table.
0
Comments
-
The easiest is to create an index (key) on that field and do a findfirst. (1)
Other solutions are to browse through the table with a variable (2) or to use the date table as temp table.(3)
If you can spare the index I would go for option 10 -
Mark Brummel wrote:The easiest is to create an index (key) on that field and do a findfirst. (1)
Other solutions are to browse through the table with a variable (2) or to use the date table as temp table.(3)
If you can spare the index I would go for option 1
Can u give me some hint on solution (2) and (3)0 -
Why do you think solution 1 does not work?
If you have more than let's say a thousand records in your table, solutions 2 and 3 will be dreadfully slow.0 -
Mark Brummel wrote:Why do you think solution 1 does not work?
If you have more than let's say a thousand records in your table, solutions 2 and 3 will be dreadfully slow.
If the table contains more then one keys then will it work0 -
mkpjsr wrote:If the table contains more then one keys then will it work
Sure it will. In fact, most tables have more than one key. It's very common to need your data sorted a certain way. In your case you want it sorted by some data field. So you add a key / index.
The trade off is that SQL (assuming you're on SQL) will take a slightly, not noticeable, longer amount of time to insert records. This is because it has to keep up with all of the indexes. You are trading a very small amount of time up front for less time down the road when you need to do calculations.0 -
Native DB needs more time as well.
If you only do this function once a day or something and if you run on SQL you can have the key in NAV but disable it on SQL.0 -
jevgjem wrote:mkpjsr wrote:Can u give me some hint on solution (2) and (3)
//variable MinDate (date)
if MyRec.findfirst then
repeat
if (MinDate > MyRec.Date) OR
(MinDate = 0D) then
MinDate := MyRec.Date;
until myRec.next=0;
But this solution is really slow on big amounts of data.
NEVER USE FINDFIRST WITH "REPEAT...UNTIL" STATEMENTS, PLEASE READ ONLINE HELP!This function should be used instead of FIND('-') when you only need the first record.
You should only use this function when you explicitly want to find the first record in a table or set. Do not use this function in combination with REPEAT..UNTIL.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions