de*********@yahoo.com wrote:
Hello,
I have a requirement where I need to return all the ids from Table1 if
the column 'name' of Table1 is in (i.e. a substring of) the 'longname'
column of Table2. How do I correct my SQL query as the below one is
showing error:
select Table1.id from Table1, Table2 where (Table2.longname LIKE
'%'||Table1.name||'%')
There is no pretty way to do this.
The migration toolkit provides a Java function with a generalized LIKE.
You can also get nasty:
CREATE PROCEDURE INSTR_P(IN string VARCHAR(128),
IN substring VARCHAR(128),
OUT found CHAR(1))
DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION
SET found = CASE WHEN string LIKE '%' || substring || '%'
THEN 1 ELSE 0 END;
--#SET TERMINATOR @
CREATE FUNCTION INSTR(string VARCHAR(128),
substring VARCHAR (128))
RETURNS CHAR(1)
DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE result CHAR(1);
CALL INSTR_P(string, substring, result);
RETURN result;
END
@
--#SET TERMINATOR ;
SELECT
Table1.id from Table1, Table2
where INSTR(Table2.longname, Table1.name) = 1
I didn't test it...
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/