Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2012-11-07 : 07:23:47
|
Hello thereI want to use the like within a where clause.All iam using is where colomn like '%_%'but i need to make that up of char numbers egselect convert(varchar(5),char(39)+char(37)+char(95)+char(37)+char(39))this will not work. is that way i can create the '%_%' sting so the query will except?RegardsRob |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-11-07 : 07:43:54
|
do u mean value which is having _ (symbol) ??Eg: a_bc _abc abc_ For the above requirement, WHERE columnName LIKE '%@_%' ESCAPE '@'------------------------------For %anycharacter% format,Eg: %b% WHERE columnName LIKE '@%_@%' ESCAPE '@'--Chandu |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-11-07 : 07:44:23
|
Not sure what you mean, the following works as I would expect returning 1, 1, and 0, respectivelyDECLARE @x VARCHAR(32) = 'xyz'+char(39)+char(37)+char(95)+char(37)+char(39)+'abc';SELECT CASE -- returns 1 WHEN @x LIKE '%'+char(39)+char(37)+char(95)+char(37)+char(39)+'%' THEN 1 ELSE 0 END; SELECT CASE -- returns 1 WHEN @x LIKE 'xyz'+char(39)+char(37)+'%' THEN 1 ELSE 0 END; SELECT CASE-- returns 0 WHEN @x LIKE 'xyzabc%' THEN 1 ELSE 0 END; |
|
|
|
|
|