IN with +'%' | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

IN with +’%’

Could I use in keyword with the ‘%’
select code from cdr
where code in (select prefix+’%’ from standard)

I beleive you can . are you getting any error messages. —————————————-

Of course you can, but it needs some adjustments for the wildcard % to actually have effect – with an IN subquery the matching is done as an equal-to operation, not a like. You might try something along these lines: select c.code from cdr c where exists (select * from standard s where c.code like c.prefix + ‘%’) You can also join on LIKE instead of equal-to: select c.code
from cdr c
inner join standard s
on c.code like c.prefix + ‘%’ Just out of curiosity: are all Prefix options of the same length? For instance, if the code is AB1234, and you have two prefixes A and AB, then they would both match.