All Forums Database
vivek2014 1 post Joined 11/14
05 Nov 2014
Multiple value in a string referring thru a variable.

Hi All,
 
I am facing one issue like below:
Table1-> column1 is having value like: 'abc','def','ghi'
i want to fetch all the records from Table2 having the same values in Column2 of this table.
Please do give your suggestions.
 
Thanks,
Vivek
ex:
sel * from tab2 where col2 in ( select col1 from table1 where <condition>);
output: No Records found.
sel * from tab2 where col2 in (  'abc','def','ghi');
output: 3 records found.
select col1 from table1 where <condition> ;
output:  'abc','def','ghi'
 
 

dnoeth 4628 posts Joined 11/04
07 Nov 2014

What's your TD release?
In TD14 you might utilize STRTOK_SPLIT_TO_TABLE like:

WITH cte (col1) as
(
  select col1 from table1 where <condition>
)
sel * from tab2 where col2 in 
 (
   SELECT  token
    FROM TABLE (STRTOK_SPLIT_TO_TABLE(1,
         cte.col1, ',')
         RETURNS (outkey INTEGER,
                  tokennum INTEGER,
                  token VARCHAR(20) CHARACTER SET UNICODE)
                 ) AS d
 )

 

Dieter

You must sign in to leave a comment.