SQLTeam.com | Weblogs | Forums

Escaping in LIKE

Hello

I am looking for find values like:
"something1"
"something1 something2"
etc
(please note the double quote marks are part of the value of the record)

How can I do this?
I think CONTAINS does not check for any punctuation and have tried to escape the double quotes with LIKE

Any idea?

Thanks!

It's very easy: just replace ' with '' so '' will be ''''. The begin and end ' will aways be single:

DECLARE @SOMETHING VARCHAR(50)

SET @SOMETHING= '''''SOMETHING'''' ELSE'

SELECT @SOMETHING

IF @SOMETHING LIKE '''''SOMETHING''''%'
SET @SOMETHING = 'YEAH'
ELSE
SET @SOMETHING = 'OH NO'

SELECT @SOMETHING

Thanks but I need to escape the double quote " which is not the same as two single quotes '' (they may appear same though, you may paste them in Word to see the difference).

How do I escape these please?

maybe

declare @odd table(col1 nvarchar(500))

insert into @odd
select '"something"' union
select '"something else"' union
select 'somethingbig' 

select * from @odd where col1 like '"%something%"'

select * from @odd

Where PatIndex( '"%something%"', col1) > 0```