Search code examples
sqlfull-text-searchsql-server-2014

Full-Text Search - How to change the declared variable to a phrase


So I am doing a FTS (Full-Text Search) on names and surnames, the issue comes in when I use spaces in either one of them.

So I have learned that using the "" inside the single quotes works. But the way I am getting these names is through a select statement and I don't know how to change that variable with the names in them to a phrase

select @fName = FirstName, @lName = LastName from Person where ....

@fName for example is John James and by doing this '"John James"' it works, but how do I do it with the above statement ?


Solution

  • So I fixed the issue by using Concat as the following

        select @LastNamePhrase =  Concat('"',@LastName,'"')
    
        print @LastNamePhrase
    
        SELECT * FROM Person WHERE (CONTAINS((Surname), @LastNamePhrase))
    

    So with this method I can do the FTS (ignore the print)