Assemble Full Text Catalog Search String

I have a field in a database that I need to assemble a string for (I'm not great with advanced string operations in t-sql).  

What the Field Contains:  John R. Smith Holding Company

The string I'd like to assemble for a full text catalog search:
"John" AND "Smith" AND "Holding" AND "Company"

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use the following function

CREATE FUNCTION [dbo].[Split] (@separator VARCHAR(32), @string VARCHAR(MAX))

        val VARCHAR(MAX)
        DECLARE @xml XML
        SET @XML = N'<root><r>' + REPLACE(@s, @sep, '</r><r>') + '</r></root>'

        INSERT INTO @t(val)
        SELECT r.value('.','VARCHAR(5)') as Item
        FROM @xml.nodes('//root/r') AS RECORDS(r)


e.g. SELECT * FROM dbo.Split(' ', 'John R. Smith Holding Company')

You can store the results of the above into a temporary table. Remove any invalid characters using the REPLACE function and any invalid rows using DELETE and then combine them using something like this:

declare @Str varchar(1000)
set @Str = ''
select @Str = @Str + CASE WHEN LEN(@Str) = 0 THEN '"' ELSE '" AND "' END + ColumnName from TableName
set @Str = @Str + '"'
u can search with this function:

string word = "Holding" // this is an example

FROM Table
WHERE Field like ("%"+word+"%") // the '%' is a jocker

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony PerkinsCommented:
I could have sworn the author was asking a question related to the use of Full-Text Search and in particular the CONTAINS clause.  I guess I was mistaken.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.