X++ query to SELECT MAX value of String type field

Donatas

I have a field in Dynamics AX 2012 table populated with serial number of PRE1 00162 format and I need to return next serial number, which in this case would be PRE1 00163.

On a legacy system it is achieved by running

SELECT MAX(RIGHT(SerialNumber,5))+1 FROM Table_Serials 
WHERE SerialNumber LIKE 'PRE1%' 

against the table on SQL server.

How can I achieve same result in X++? My guess so far is

select maxof(right(SerialNumber,5))+1
    from tableSerials
    where tableSerials.SerialNumber 
like tableSerials;

but it shows syntax error starting right after maxof(right( part.

Thank you!

Donatas

One of my wise colleagues have also suggested this method, which also works:

static void CompNextSerial(Args _args)
{
    str value;
    int num;
    str 10 prefix;
    SerialsTable serialsTable;

    prefix = "PRE1 *";

    select firstOnly serialsTable
        order by SerialNumber desc
        where serialsTable.SerialNumber like prefix;

    value = subStr (serialsTable.SerialNumber, strLen(serialsTable.SerialNumber) - 4 , 5);
    num = str2int(value) + 1;
    info (strFmt('%1', num));
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Distinct value from array looking field type that is a string?

分類Dev

Unable to pass Import Value in Type:String field in Cloudformation

分類Dev

select max sequence number in query

分類Dev

Select data with max date order by another field

分類Dev

Drupal - Query to count all nodes of content_type "A" in which field_b is "X"

分類Dev

How do I query a field from Mongo where the value is actually a number but stored as string?

分類Dev

string is value type or reference type?

分類Dev

SQL select distinct value where Status = MAX

分類Dev

SQL Query for max value from subsets

分類Dev

max value of no autonincrement column in update query - Oracle

分類Dev

How to print a field type on oracle without a `SELECT`

分類Dev

Correct regex for matching the string with max number value

分類Dev

Doctrine Priority select depends on a field value

分類Dev

Rails nested forms select field default Value

分類Dev

Is it possible to query field name by it's value in MongoDB?

分類Dev

Adding fake field value to database query

分類Dev

Ansible Warning "type list in a string field was converted to type string"

分類Dev

Mongodb: Query with a field value, but also another unknown unique field

分類Dev

Get custom field value and max price from variation product in WooCommerce

分類Dev

oracle-sql query select max from each base

分類Dev

Go: type []string has no field or method len

分類Dev

Get the String mongo field data type in java

分類Dev

MS Acess: max(Date/Time field) on query when field may contain 00:00:00

分類Dev

Select into with max()

分類Dev

Generate dynamic series in select query with computed value

分類Dev

SQL query to select prior record based on value

分類Dev

How return null value to empty string field

分類Dev

Extract string from value and insert into field

分類Dev

How to define a generic type that is a string field of another type?

Related 関連記事

  1. 1

    Distinct value from array looking field type that is a string?

  2. 2

    Unable to pass Import Value in Type:String field in Cloudformation

  3. 3

    select max sequence number in query

  4. 4

    Select data with max date order by another field

  5. 5

    Drupal - Query to count all nodes of content_type "A" in which field_b is "X"

  6. 6

    How do I query a field from Mongo where the value is actually a number but stored as string?

  7. 7

    string is value type or reference type?

  8. 8

    SQL select distinct value where Status = MAX

  9. 9

    SQL Query for max value from subsets

  10. 10

    max value of no autonincrement column in update query - Oracle

  11. 11

    How to print a field type on oracle without a `SELECT`

  12. 12

    Correct regex for matching the string with max number value

  13. 13

    Doctrine Priority select depends on a field value

  14. 14

    Rails nested forms select field default Value

  15. 15

    Is it possible to query field name by it's value in MongoDB?

  16. 16

    Adding fake field value to database query

  17. 17

    Ansible Warning "type list in a string field was converted to type string"

  18. 18

    Mongodb: Query with a field value, but also another unknown unique field

  19. 19

    Get custom field value and max price from variation product in WooCommerce

  20. 20

    oracle-sql query select max from each base

  21. 21

    Go: type []string has no field or method len

  22. 22

    Get the String mongo field data type in java

  23. 23

    MS Acess: max(Date/Time field) on query when field may contain 00:00:00

  24. 24

    Select into with max()

  25. 25

    Generate dynamic series in select query with computed value

  26. 26

    SQL query to select prior record based on value

  27. 27

    How return null value to empty string field

  28. 28

    Extract string from value and insert into field

  29. 29

    How to define a generic type that is a string field of another type?

ホットタグ

アーカイブ