Wednesday, March 28, 2012

How to construct a like compariso when there are special chara

select *
from
(
select 'abc[Y]def' as c1
union all
select 'abcdef' as c1
) as t1
where c1 like '%\[Y\]%' escape ''
go
AMB
"Alejandro Mesa" wrote:
> bic,
> use a scape character.
> Example:
> select *
> from
> (
> select 'abc[Y]def' as c1
> union all
> select 'abc[Y]def' as c1
> ) as t1
> where c1 like '%\[Y\]%' escape ''
> go
>
> AMB
> "bic" wrote:
>"SQL Menace" <denis.gobo@.gmail.com> wrote in message
news:1149792727.734355.86450@.u72g2000cwu.googlegroups.com...
> Another way is to double the brackets
> select *
> from
> (
> select 'abc[Y]def' as c1
> union all
> select 'abcYdef' as c1
> ) as t1
> where c1 like '%[[Y]]%'
> go
>
Be careful with the bracket doubling thing - it can get confusing on complex
comparisons with lots of [ ]'s in them.

No comments:

Post a Comment