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
 Development Tools
 ASP.NET
 Double quotes misery in SQL

Author  Topic 

eddd
Starting Member

1 Post

Posted - 2004-06-14 : 15:07:19

I am stuck trying to pass a search phrase from my .NET app using the CONTAINS() method in SQL.

My SQL Server database has a table with a "contents" column that has full text indexing. In order to search for several words the CONTAINS query must use a combination of single and double quotes:

CONTAINS(contents, '"cats and dogs"')

I want to pass a search phrase variable into this statement from .NET (using a stringBuilder) like this:

sb.Append(" AND CONTAINS(contents, " + searchTerm + ")");

But I cannot see how to pass the quotes and double quotes into SQL.

Is there an easier way of doing this??

Many thanks,

ed

nr
SQLTeam MVY

12543 Posts

Posted - 2004-06-14 : 15:19:19
You want to add the "' ?
sb.Append(" AND CONTAINS(contents, '""" + searchTerm + """')");

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -