Hello All,
I have a string column from which i need to extract all columns containing 'XXX' AND 'YY' . These two can appear at any length of string but will always be together(i.e 3X will be together and 2 Y will b together).
Please suggest how to implement this.
Database is DB2
Quote from: nsaxena on 23 Mar 2017 04:19:54 PM
Hello All,
I have a string column from which i need to extract all columns containing 'XXX' AND 'YY' . These two can appear at any length of string but will always be together(i.e 3X will be together and 2 Y will b together).
Please suggest how to implement this.
Database is DB2
Find out if your version of DB2 has support for regexp built-in functions.
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/db2/rbafzscaregexp_instr.htm
Also consider the locate or position function to identify if the column has the string or not.
If existence of those partial strings is all you're looking for, especially without any demands to the surroundings of the partial strings, you don't need regex for that.
if(
(position('XXX',[string])>0) and (position('YY',[string])>0)
)
then (1)
else (0)
and filter for 1
There is also the function 'contains' that you can also use in query filters.