Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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:
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'
 
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'.
Posted 21-Jan-13 7:41am
Edited 21-Jan-13 8:47am
RedDk10.3K
v3
Comments
richcb at 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
good
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'
 
SELECT [FORENAME] FROM [PERSON]]
WHERE CONTAINS( [FORENAME], @name )
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 ...
  Permalink  

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

  Print Answers RSS
0 DamithSL 440
1 OriginalGriff 194
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 163
0 OriginalGriff 7,934
1 DamithSL 6,084
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,174
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
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