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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 escape double quotes in a string

Author  Topic 

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-07-29 : 11:51:57
Hi all,

I want to escape double quotes passing from a string into a stored procedure.. here is the actual query i used to escape double quotes but nothing seems to work,


*************
SELECT * FROM TABLE
WHERE
USER_FIRSTNAME LIKE +'%'+'"'+@ss+'"'+'%'
or USER_LASTNAME LIKE +'%'+'"'+@ss+'"'+'%'
or TITLE LIKE +'%'+'"'+@ss+'"'+'%'

********************

@ss is the string which has double quotes and using a like operator.

Appreciate your help.
thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-29 : 11:54:44
use REPLACE function. look into books online for syntax & usage.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-07-29 : 11:57:02
Did you try using teh ESCAPE clause?

From BOL:
match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ]

Example:
SELECT c1 
FROM mytbl2
WHERE c1 LIKE '%10-15!% off%' ESCAPE '!'


Go to Top of Page

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-07-29 : 12:17:06
ESCAPE '"' doesn't work for me..

i used replace function like this below..but still doesn't work.. any clues

select @sss = REPLACE(@ss, '"', '''')
Go to Top of Page

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-07-29 : 12:24:06
am using @ss variable inside a like operator " like '%@ss%' that's y am unable to apply replace..
Go to Top of Page

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-07-29 : 12:31:10
i got it

select @sss = REPLACE(@ss, '"', '')

used two single quotes to solve it
Go to Top of Page
   

- Advertisement -