Solved

Escape ~ character for use in tsql contains() function

Posted on 2009-03-29
3
1,073 Views
Last Modified: 2012-05-06
Hi,

I'm using SQL server 2000 and I want to search for records that contain the ~ character in the text. Something like this:

select * from tblText where contains(txt, '~')

Apparently that will not work as ~ character is actually the NEAR operator.

How can I escape it? I wouldn't want to use LIKE expresssion as I want to take advantage of contains() and  its full text index.

Thanks a lot.
0
Comment
Question by:Squarenine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Assisted Solution

by:mildurait
mildurait earned 20 total points
ID: 24015276
~ is ascii character 126

Therefore you can use
SELECT * FROM tblText WHERE contains(txt,char(126))
0
 

Accepted Solution

by:
Squarenine earned 0 total points
ID: 24016167
Hi,

Unfortunately, contains(txt,char(126)) causes a syntax error.

I finally went with::

select * from tblText where charindex('~', txt') > 0

and it works great.

Still want to know how to escape ~ in contains function though.

Thanks anyway.
0
 

Author Comment

by:Squarenine
ID: 24016179
ok
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question