views:

60

answers:

4

Hi I am facing a problem with the like command in SQL,

I want to search for special characters within a column . The special characters are a single quotation mark ' and { and }..

I have tried placing these special characters under [] but still it doesn't work for '

I have also used the except option but that was also of no help..

Waiting for a response soon

+1  A: 

When you specify a value which has single quote, you need to double it.

SELECT  *
FROM    dbo.Northwind
WHERE   Summary LIKE 'single''quotes%'
Lieven
Does this work for the oracle database also ???just in case if u have any idea???
Egalitarian
@Egalitarian, as far as single quotes goes, it's the same for Oracle.
Lieven
+1  A: 

Try using this-

select * from <table> where <column> like '%''%' 
Sachin Shanbhag
Does this work for the oracle database also ???just in case if u have any idea
Egalitarian
@Egalitarian, as far as single quotes goes, it's the same for Oracle.
Lieven
A: 

SQL Server escaping is a pain because there are various ways to escape characters, each with different meaning and use case.

A single quote is escaped with another single quote: WHERE myfield LIKE '%''%'.

chryss
Does this work for the oracle database also ???just in case if u have any idea
Egalitarian
@Egalitarian, as far as single quotes goes, it's the same for Oracle.
Lieven
A: 

The general solution is to escape the special character like so:

SELECT .... WHERE my_column like '%\'%' ESCAPE '\'
mwittrock
hey that didn't work..
Egalitarian
http://msdn.microsoft.com/en-us/library/aa933232(SQL.80).aspx
mwittrock
even i was shocked when that didn't work when i initially tries...thanx anyways
Egalitarian