Match exact match partial phrase SQL

hi

i want to do the following

                    |---------------------------|
Enter Phrase  |___________________|   o Match Exact

i have a textbox and a checkbox on a webpage, i want to the user to be a able to enter a search                                                                                                 a description field in a database table,

if they enter 'redhat linux', and dont click match exact, i want rows to be returned if eiter 'redhat' or 'linux' or 'redhat linux' appear in the description field, and if they check the match exact field then only rows with 'redhat linux' should be returned,

is there an easy way to do this in sql, or do i have to split the search string then do seperate searches, then combine the search results then remove duplicate rows??

also if i do this 'WHERE description LIKE %linux%' will this bring back records where linux is the first word in the description, or would i have to do seperate sql searchs for %linux%, linux%, and %linux,
stephencushenAsked:
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.

stephencushenAuthor Commented:
thanks in advance
0
pique_techCommented:
I *think* you have to separate out the various components, because if you did
     Like '%redhat%linux%'
you'd only get those records that had those words, in that order, somewhere in the search field.

So what you really want is
    Like '%linux%' OR Like '%redhat%'
I don't know how you'd do that in one (relatively simple) SQL statement.

If you do
     Like '%linux%'
you'll get anything with 'linux' in it anywhere, beginning, middle, or end.

0
OlegPCommented:
'linux%'    begin
'%_linux_%' middle
'%linux' end
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

illCommented:
create proc getBySearched
@phrase nvarchar(3000),
@exact int= 0
AS
declare @text nvarchar(4000)
set @text= ' select * from w2string  where val like ''' + replace ( ' '+ @phrase+' ', ' ', case @exact when 1 then ' ' else '%' end)  +''''
--print @text
exec  ( @text)
0
illCommented:
-- sorry, posted with my test tables. replace mytable with your table name
create proc getBySearched
@phrase nvarchar(3000),
@exact int= 0
AS
declare @text nvarchar(4000)
set @text= ' select * from myTable  where description like ''' + replace ( ' '+ @phrase+' ', ' ', case @exact when 1 then ' ' else '%' end)  +''''
--print @text
exec  ( @text)
0
Anthony PerkinsCommented:
I strongly urge you to take a look at SQL Server's Full-Text search capabilities.  It looks like you are trying to re-invent the wheel.
0

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
stephencushenAuthor Commented:
full-text serching seems to be the way to go, but i cant use it till i get mssql server, im using msde for development
 
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.