|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to construct a like compariso when there are special charactsHow do I construct a like compariso query when there are special characts
such as [ and ] in the string, i.e. [Y] to be searched? Thanks. -- bic 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 Show quote "bic" wrote: > How do I construct a like compariso query when there are special characts > such as [ and ] in the string, i.e. [Y] to be searched? Thanks. > -- > bic select *
from ( select 'abc[Y]def' as c1 union all select 'abcdef' as c1 ) as t1 where c1 like '%\[Y\]%' escape '\' go AMB Show quote "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: > > > How do I construct a like compariso query when there are special characts > > such as [ and ] in the string, i.e. [Y] to be searched? Thanks. > > -- > > bic 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 Denis the SQL Menace http://sqlservercode.blogspot.com/ Alejandro Mesa wrote: Show quote > 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: > > > > > How do I construct a like compariso query when there are special characts > > > such as [ and ] in the string, i.e. [Y] to be searched? Thanks. > > > -- > > > bic
Show quote
"SQL Menace" <denis.g***@gmail.com> wrote in message Be careful with the bracket doubling thing - it can get confusing on complex 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 > comparisons with lots of [ ]'s in them. You can use the ESCAPE clause. In this example I'm using '!' as the escape
character: DECLARE @x VARCHAR(100) SELECT @x = '[Y]' SELECT CASE WHEN @x LIKE '![Y!]' ESCAPE '!' THEN 'Match' ELSE 'No Match' END AS Answer Show quote "bic" <b**@discussions.microsoft.com> wrote in message news:B548D713-0022-47D1-A0E4-47630561159C@microsoft.com... > How do I construct a like compariso query when there are special characts > such as [ and ] in the string, i.e. [Y] to be searched? Thanks. > -- > bic |
|||||||||||||||||||||||