How can I sort code fields?

kirkostas
Member Posts: 127
Hi,
I have a table and I want to retrieve the maximum value of a code field.
My code field values are 1 - 10.
I sort my table but FINDLAST retrieves always the value 9 because the value 10 is under the value 1. What can I do to retrieve the correct value?
Thank you.
I have a table and I want to retrieve the maximum value of a code field.
My code field values are 1 - 10.
I sort my table but FINDLAST retrieves always the value 9 because the value 10 is under the value 1. What can I do to retrieve the correct value?
Thank you.
kirkostas™
0
Answers
-
-
Does your CODE-field only contains numbers or also characters?
If you have "B1" and "A10" as values for example, what do you consider to be the largest value?No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
// update "Tax Office" table TaxOfficeRec.SETRANGE(TaxOfficeRec.Name,"Tax Office"); IF NOT TaxOfficeRec.FINDFIRST THEN BEGIN TaxOfficeRec.RESET; TaxOfficeRec.ASCENDING(TRUE); IF TaxOfficeRec.FINDLAST THEN EVALUATE(TaxOfficeRecID,FORMAT(TaxOfficeRec.Code)); TaxOfficeRecID += 1; TaxOfficeRec.LOCKTABLE; EVALUATE(TaxOfficeRec.Code,FORMAT(TaxOfficeRecID)); TaxOfficeRec.Name := "Tax Office"; TaxOfficeRec.INSERT; END;
I have the same problem again. The sorting order of the table is:
1
10
2
3
4
5
6
7
8
9
and I want to get the value 10 but it returns me the value 9.kirkostas™0 -
-
You are trying to sort a text field as number. unfortunatelly this is not for navision.
As i see from your code you are trying to migrate data in your tax office table. This must be done once or multiple times?0 -
That is why I need to sort the table with the code field because I want to have the next available value to insert my data. I want to insert about 100 records in Tax Office table.
fidel I have added you in my Skype account if you want to discuss a little more.kirkostas™0 -
You can create a new Integer-field in your table and copy the contents of your Code-field to this field. Then create a new key on this Integer-field and you are set.
Alternative is to use a REPEAT .. UNTIL construction to loop through all records, and use a IF rec.Codefield > intLargestValue THEN intLargestValue := rec.Codefield statement to store the largest value in a variable.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
kirkostas wrote:Hi,
I have a table and I want to retrieve the maximum value of a code field.
My code field values are 1 - 10.
I sort my table but FINDLAST retrieves always the value 9 because the value 10 is under the value 1. What can I do to retrieve the correct value?
Thank you.
This is how SQL sorts code fields. If it really is only 10 values, you could o it in code. If its a lot more, then set the Sort type to Integer in the Table designer.David Singleton0 -
I was in the same trouble on the past week, because I have a database that is restored under SQL Server. And I cannot run over the whole tables to expand the length of the code fields...
But I think you create a job where does not get the no from the No.Series to set that code values to same length... :?
Is any idea how can I set the SQL database (without any programming) to the correct sorting?
I cannot believe that is not any settings to solve this problem. Or this is only my problem0 -
Asallai wrote:I was in the same trouble on the past week, because I have a database that is restored under SQL Server. And I cannot run over the whole tables to expand the length of the code fields...
But I think you create a job where does not get the no from the No.Series to set that code values to same length... :?
Is any idea how can I set the SQL database (without any programming) to the correct sorting?
I cannot believe that is not any settings to solve this problem. Or this is only my problem
Go to properties for the field and change "SQL Data Type" to integer.David Singleton0 -
I don’t want to change the SQL Data Type of the field Code in Tax Office table. So I come with a solution to my problem. Using the INCSTR function I have created a pre-fix for my inserted data. For example I use the “TAX-000001”. So I do a SETFILTER in Code field for “TAX*” and I do a FINDLAST so I have my last value and I increase the value using INCSTR function.
// update "Tax Office" table IF "Tax Office" <> '' THEN BEGIN TaxOfficeRec.SETRANGE(TaxOfficeRec.Name,"Tax Office"); IF NOT TaxOfficeRec.FINDFIRST THEN BEGIN IF TaxOfficeRecCode = '' THEN BEGIN TaxOfficeRecCode := 'TAX-000001'; TaxOfficeRec.RESET; TaxOfficeRec.SETFILTER(TaxOfficeRec.Code,'TAX*'); IF TaxOfficeRec.FINDLAST THEN BEGIN TaxOfficeRecCode := TaxOfficeRec.Code; TaxOfficeRecCode := INCSTR(TaxOfficeRecCode); END; END ELSE TaxOfficeRecCode := INCSTR(TaxOfficeRecCode); IF TaxOfficeRec.HASFILTER THEN TaxOfficeRec.RESET; TaxOfficeRec.LOCKTABLE; TaxOfficeRec.Code := TaxOfficeRecCode; TaxOfficeRec.Name := "Tax Office"; TaxOfficeRec.INSERT; END; END;
Thank you all =D>kirkostas™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