Use variable in IN statement

Anybody succeeded in using a variable with a IN statement?
Sort of
IF AnyRecord.Field IN [TextVariable] THEN ...
where TextField should contain something 'VALUE1,VALUE2,VALUE3'.

Thanks

Answers

  • NavNabNavNab Member Posts: 181
    I don't know which NAV version you use! If NAV2009 SP1 RTC or newer then you can try .NET interoperability using List.Contains
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    IF SomeVar IN [TextVariable] THEN ... has no chance to work. You can try to think of IN operator as a series of ORs on every argument inside the square brackets. In your case IF SomeVar IN [TextVariable] THEN... is equivalent to IF SomeVar = TextVariable THEN... as you have only one argument inside the square brackets.

    Without restoring to .NET you can write a function performing the check, someting like this:
    Contains(aVar, aList)
    {
      EXIT(
       (aVar = aList)
        OR (STRPOS(aList,    aVar+',') = 1)
        OR (STRPOS(aList, ','+aVar+',') > 1)
        OR (STRPOS(aList, ','+aVar) = STRLEN(aList) - STRLEN(aVar) )
      )
    }
    

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • tarkmylertarkmyler Member Posts: 57
    edited 2018-05-11
    2009r2 classic client - square brackets for IN statement
    Mark Tyler
    Pacific City, OR
Sign In or Register to comment.