3 Replies Latest reply: Mar 12, 2018 9:32 AM by Justin Dallas RSS

    Variable Expansion in Match

    Justin Dallas

      Hello Folks,

       

      I've got a small variable expansion in a Match statement that isn't working like I think it should work.  It looks something like this.

       

      SET vCompanies = 'McDonalds,BurgerKing'
      ;
      Menu:
      LOAD * WHERE 
      MATCH(Restaraunt, '$(vCompanies)')
      ;
      LOAD * Inline
      [
      'Id', 'Restaraunt', 'Food'
          1, 'McDonalds', 'Broken McFlurry Machine'
          2, 'McDonalds', 'Big Mac'
          3, 'BurgerKing', 'Whopper'
          4, 'BurgerKing', 'Whopper Jr.'
          5, 'Wendys', 'Frosty'
      ]
      ;
      

       

       

      The issue,  is that the vCompanies variable isn't being split and put into the Match statement.  I expected, maybe naively, that my variable would be expanded and all would be well.

       

      Any help on getting my list into a variable and into a MATCH statement is greatly appreciated.

        • Re: Variable Expansion in Match
          Fernando Obara Suzuki

          TRY LIKE THIS:

           

           

          SET vCompanies = 'McDonalds','BurgerKing';

           

          Menu:

          LOAD * WHERE

          MATCH(Restaraunt, $(vCompanies))

          ;

          LOAD * Inline

          [

          'Id', 'Restaraunt', 'Food'

              1, 'McDonalds', 'Broken McFlurry Machine'

              2, 'McDonalds', 'Big Mac'

              3, 'BurgerKing', 'Whopper'

              4, 'BurgerKing', 'Whopper Jr.'

              5, 'Wendys', 'Frosty'

          ]

          ;

          • Re: Variable Expansion in Match
            Manish Kachhia

            Use something like this..

             

            SET vCompanies = 'McDonalds','BurgerKing';  
            
            
            Menu:  
            LOAD 
             * 
            WHERE   
             MATCH(Restaraunt, $(vCompanies));  
            LOAD * Inline  
            [  
             Id, Restaraunt, Food  
                1, McDonalds, Broken McFlurry Machine  
                2, McDonalds, Big Mac  
                3, BurgerKing, Whopper  
                4, BurgerKing, Whopper Jr.  
                5, Wendys, Frosty  
            ]  
            ;
            

             

            Or use something like below.

             

            Temp:
            Load * Inline
            [
             Company
             McDonalds
             BurgerKing
            ];
            
            
            Menu:  
            LOAD * Inline  
            [  
             Id, Restaraunt, Food  
                1, McDonalds, Broken McFlurry Machine  
                2, McDonalds, Big Mac  
                3, BurgerKing, Whopper  
                4, BurgerKing, Whopper Jr.  
                5, Wendys, Frosty  
            ]Where Exists(Company,Restaraunt);
            
            
            Drop Table Temp;