Problem with SETFILTER, OR operator

naranara Member Posts: 37
Hi!
I need some help about a SETFILTER.
I have an Itemrecord that I want to filter by Class in such way that my Itemrecord included item that have these (several) class value.
What could be equivalent to one of the following SQLquery
select * from Item where Calss in ('class1', 'class2'..... , 'classn')
OR
select * from Item where Class = 'class1' OR Class = 'class2'..... OR Calss = 'classn'

I want some thing like that in my CODEUNIT
ItemRecord.SETFILTER("Class", and I do not no how to handle the rest :oops: );

best ergards
Nasser

Comments

  • garakgarak Member Posts: 3,263
    first: You are in the wrong forum section :-)

    second try following:
    ItemRec.Setfilter("Class",'%1|%2|%3','TABLE','STOOL','CHAIR');
    

    if you need the filter dunymicly, you can fill a variable and use the variable as filter

    Regards
    Do you make it right, it works too!
  • DenSterDenSter Member Posts: 8,305
    Note that the maximum filterstring length is 250 characters, so you can't do that forever. I've seen programming like that fail because the required filter is too long.
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,499
    [Topic moved from Navision Tips & Tricks to Navision forum]
  • girish.joshigirish.joshi Member Posts: 407
    edited 2008-05-30
    Typically what you have to do is build the string dynamically, all the while checking to see if you have exceeded 250 characters. Once you exceed you build another string for the reminder (and so on). Then you get all of your mutually exclusive result sets and push them all into a temporary record.

    A huge pain, but it works.

    Usually people do this kind of thing when they want to do something like a SQL join ( or a select * where in) in NAV, but they can't.

    For small data sets, it makes sense to just loop through all of the items, and insert them into a temporary record if they match your criteria.

    For larger data sets, your best option is use to use ADO. When using ADO remember to build your SQL string in NAV and not use a stored procedure.

    Getting into the mess of managing stored procs. just so you can make one query is a huge waste of time.
  • girish.joshigirish.joshi Member Posts: 407
    Just for a sense of scale... to me a large data set would be where you have a GB or so of items.
Sign In or Register to comment.