Click here to Skip to main content
12,884,771 members (29,702 online)
Rate this:
Please Sign up or sign in to vote.
See more: SQL-Server

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:
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:
declare @name nvarchar(30)
set @name = N'Barack Hussain Obama'
FROM Person

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'.
Posted 21-Jan-13 6:41am
Updated 21-Jan-13 7:47am
richcb 21-Jan-13 12:46pm
You have an "N" after the equal sign and before your string value when setting @name.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The minimum required here, as long as you've managed to full-text index this table "PERSON", is:
DECLARE @name [nvarchar](30)
SET @name = 'Barack'

That being said, in order to search for this string:
SET @name N'Barack Hussain Obama'

You'd have to be concatenating two fields, ie-> [FORENAME] + [SURNAME], which would quickly make a simple search run through a table of first & last names quite a but more difficult. My solution, as begun, would entail searching through once, for either the FORE or SUR, getting all the results ... tabulating them, then searching again, after making THAT table FULL-TEXT INDEXED, for the second part. I don't see any real logic to trying to concatenate first and last then looping through another table of concatenations ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100