Options

SETFILTER on Code datatype field

navuser1navuser1 Member Posts: 1,329
edited 2014-10-20 in NAV Three Tier
Sir,

Please guide me to filter out the below bound information on a Table.

Suppose A table is build a field(pk) called Value (Data type Code 20).
Table contains the record for the field Value starting from 1 to 9999999.
Now I want to filter the Table Data starting range from 9710101 to 9710399 and 9640601.

Currently I have handled the scenario with the help of EVALUATE function.

Thank you.
Now or Never

Comments

  • Options
    matteo_montanarimatteo_montanari Member Posts: 189
    navuser1 wrote:
    Sir,

    Please guide me to filter out the below bound information on a Table.

    Suppose A table is build a field(pk) called Value (Data type Code 20).
    Table contains the record for the field Value starting from 1 to 9999999.
    Now I want to filter the Table Data starting range from 9710101 to 9710399 and 9640601.

    Currently I have handled the scenario with the help of EVALUATE function.

    Thank you.

    Hi

    From a SQL prospective a "Code" Field type is a standard nvarchar like a "Text" field type.
    So if you put an integer to a text field you will see a sort like:
    1
    10
    11
    2
    3
    35
    36
    37
    9
    99

    If you place a setrange(mytextfield, '2', '5') you will receive "2","3","35","36","37".

    You must usa an appropriate field type like "Integer" or place some "0" before your number.
    something like:

    001
    002
    003
    009
    010
    011
    035
    036
    037
    099

    The alphabetic order will be similar to integer sequence.

    Bye

    Matteo
    Reno Sistemi Navision Developer
  • Options
    BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Matteo is correct.

    However, for that very specific example you present, the range-numbers have the same number of digits, so you can write your filter simply like this:

    SETFILTER(Value,'9710101..9710399|9640601');

    But note that it would not work if the from/to range values had different number of digits.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • Options
    navuser1navuser1 Member Posts: 1,329
    What I have done to handle this....
    // Save my bound data into a temporary Table Begin
    TempInteger.DELETEALL;
    RecInteger.RESET;
    RecInteger.SETFILTER(RecInteger.Number,'%1..%2|%3',9710101,9710399,9640601);
    IF RecInteger.FINDSET THEN
     REPEAT
       TempInteger.INIT;
       TempInteger.COPY(RecInteger);
       TempInteger.INSERT;
     UNTIL RecInteger.NEXT =0;
    // Save my bound data into a temporary Table End
    
    //Finding the data which I have to check into above temp table Begin
    ...........
    ...........
    ...........
    //Finding the data which I have to check into above temp table End
    
    // Convert into int Begin
    EVALUATE(VarInteger, Code datatype field);
    // Convert into int End;
    
    // Check the Range Begin
    IF NOT TempInteger.GET(VarInteger) THEN
        ERROR(..);
    
    // Check the Range End;
    
    Now or Never
  • Options
    navuser1navuser1 Member Posts: 1,329
    But note that it would not work if the from/to range values had different number of digits.

    Sir,

    Above mentioned line force me to knock the expert door. [-o<
    Now or Never
Sign In or Register to comment.