Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Escaping special characters Full text index search Expand / Collapse
Author
Message
Posted Wednesday, January 16, 2008 2:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 16, 2008 9:44 AM
Points: 1, Visits: 9
I have created a full text index on a column of a table. The issue is i need to search for AT&T.
the query i use for search is

SELECT * FROM TABLE_NAME WHERE CONTAINS(COLUMN_NAME, '"AT&T*"')

It returns many records but doesn't return the records with AT&T in it. I guess '&' is killing it, but i have no idea how to escape it in case of full text index search.
Any help will be deeply appreciated.

Post #444012
Posted Sunday, July 8, 2012 4:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 16, 2013 4:37 AM
Points: 8, Visits: 45
The '*' is killing you. Use '%' instead.

If you want to search for text that for example contains % or other special characters you have to escape them.
See the example below:

SELECT * FROM
(
SELECT UserName + '&%' + Email AS A FROM Employees
) G
WHERE G.A LIKE '%s&!%x%' ESCAPE '!'

I am concatenating two fields adding &% in between. No escaping needed there.
And I want to look for any record that has the literal pattern 's&%x' inside it

So in the LIKE however, I start with an '%s (the equivalent of *), follow with an 's', follow with an '&' (no escaping needed) and then I escape the '%' using any character I like, so I chose '!'. Then follows 'x' and '%' for the rest of the string.

Pretty straightforward right?

Cheers
Dimitris
Post #1326556
Posted Sunday, July 8, 2012 12:27 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:48 AM
Points: 36,759, Visits: 31,214
dimitris.staikos (7/8/2012)
The '*' is killing you. Use '%' instead.


Keep in mind that this isn't standard T-SQL. It's Full Text Search.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1326600
Posted Wednesday, July 18, 2012 4:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 16, 2013 4:37 AM
Points: 8, Visits: 45
Yeah, you are right, thanks
Post #1331356
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse