fc123
fc123

Reputation: 918

how can I search string with double single quotes (sql)

I have a varchar field LOCATIONCITY and there is a value

St. John''s

I want to search it like following

select * from city where locationcity='St. John''s'

Since it's a default behavior of sql server that double single quotes are converted to single double qoites

How can I search for 'St. John''s'

Upvotes: 2

Views: 840

Answers (2)

Dgan
Dgan

Reputation: 10295

Try this:

DECLARE @Name varchar(100)='St. John''s'
set @Name=REPLACE(@Name,'''','''')
select @Name

Upvotes: 1

Mureinik
Mureinik

Reputation: 311808

You have two single quotes, each one of which should be escaped by doubling it, so:

select * from city where locationcity='St. John''''s'

Upvotes: 6

Related Questions