Friday, February 24, 2012

How to Combine IN & LIKE

Hai All,
Could some one help me how to combine IN & LIKE in the query selection,
i'v try many syntac and i just have no find the way out Sad

this is what I would like to write:

Select DSCRIPTN,ORMSTRID,ACTINDX
from T50001
where ACTINDX = 350
and DSCRIPTN Like in '%'+(select distinct rtrim(ORMSTRID) ORMSTRID from L10001)+'%'

hi,

you can not combine the two keywords... as you can see from BOL synopsis, LIKE expects an expression and not a multiple reusult.. and you can not combine the expression as you require..

you probably have to rewrite your subquery to retun something comparable with the main query result's primary key.. the LIKE operator should probably go inside the subquery..

regards

|||

Something like:

Select DSCRIPTN,ORMSTRID,ACTINDX
from T50001
where ACTINDX = 350
and EXISTS
(

select * FROM L10001 WHERE DSCRIPTN LIKE '%' + ORMSTRID +'%'

)


If you have multiple entries in the L10001 table you should use a subquery which create the DISTINCT values on the fly.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment