Click here to Skip to main content
15,886,063 members

Name search with Full Text Search

Quarenta asked:

Open original thread
Hello.

I'm having trouble implementing a query for searching names on a table PERSON, which has two columns, FORENAME and SURNAME.

I'll use FULL TEXT SEARCH for doing that, and already have created the FULL TEXT CATALOG and the FULL TEXT INDEX on this table.

Supposing that i have the following rows on the table:
CSS
1. FORENAME: "Barack"     SURNAME: " of Mortal Kombat"
2. FORENAME: "Sadam"      SURNAME: "Houssein"
3. FORENAME: "Crystal"    SURNAME: "Obakwelu"

And i'm trying to search this name:

. Name to search: "Barack Hussain Obama"

I would do the sql query like this, supposing that @name is a parameter, and it would be passed by the user through the application layer, like a C# program:
SQL
declare @name nvarchar(30)
set @name = N'Barack Hussain Obama'

select FORENAME, SURNAME
FROM Person
WHERE CONTAINS( (FORENAME, SURNAME), @name )

How can i get this working? The problem is in the @name string.
ERROR: Syntax error near 'Hussain' in the full-text search condition 'Barack Hussain Obama'.
Tags: SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900