SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 escape double quotes in a string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chava_sree
Yak Posting Veteran

USA
56 Posts

Posted - 07/29/2008 :  11:51:57  Show Profile  Reply with Quote
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

India
52325 Posts

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

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 07/29/2008 :  11:57:02  Show Profile  Reply with Quote
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

USA
56 Posts

Posted - 07/29/2008 :  12:17:06  Show Profile  Reply with Quote
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

USA
56 Posts

Posted - 07/29/2008 :  12:24:06  Show Profile  Reply with Quote
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

USA
56 Posts

Posted - 07/29/2008 :  12:31:10  Show Profile  Reply with Quote
i got it

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

used two single quotes to solve it
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000