8 Replies Latest reply: Oct 30, 2018 2:49 PM by Amuktha Chakilam RSS

    Multiple values from variable in where condition in SQL query

    Amuktha Chakilam

      Hi all,

       

      I have a variable vField . Its value is  'a','b','c','d'

       

      How do I write a SQL query to check where field matches any values (a or b or c or d) in vField variable?


      Thanks!

       

       

       

      LIB CONNECT TO database1;

       

      Table1:

      Load Field,

      1 as PlaceHolder;

       

      select distinct Field from db1.xyz

      where ....

      ;

       

       

      Table2:

      load

      Concat(chr(39)&Field &chr(39),',') as Field_new

      Resident Table1

      Group by PlaceHolder;

       

      Drop Table Table1;

       

       

      let vField = Peek('Field_new', 'Table2');

       

      Drop Table Table2;

       

      LIB CONNECT TO database2;

      Data:

      Load *;

      sql select * from

      db2.abc

      where Field_table2 in $(vField)