[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TSQL Search on String

Posted on 2010-09-17
6
Medium Priority
?
826 Views
Last Modified: 2012-05-10
Hi Experts,

I would like to create a stored proc that would search on the exact term keyed in (could be one word or phrase and then search on the seperate words in the phase:

Sample Search "Experts Exchange"
WHERE = like 'experts exchange' OR like 'experts' OR like 'exchange'

What is the best practice for this (speed etc)? Im going to take out all stop words so I just get a search on only the keywords typed.

Regs,
Numb
0
Comment
Question by:ComfortablyNumb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 668 total points
ID: 33700903
this sounds like a FULL TEXT index candidate:
http://msdn.microsoft.com/en-us/library/ms187317.aspx

once you create and ensure the full text catalog is populated/updated regularly, you can use the CONTAINS, CONTAINSTABLE,  FREETEXT or FREETEXTTABLE methods
http://technet.microsoft.com/en-us/library/ms187787.aspx
0
 
LVL 7

Assisted Solution

by:tlovie
tlovie earned 664 total points
ID: 33700906
Sounds like a job for full text indexing.

Have a look at this... it's not trivial to set up, but the other options for doing the search as you describe, may end up lacking in robustness.

http://www.developer.com/db/article.php/3446891/Understanding-SQL-Server-Full-Text-Indexing.htm
0
 

Author Comment

by:ComfortablyNumb
ID: 33701083
You would think so. But unfortuately my live version of SQL Server hasn't got it installed (Standard Edition SP3) and our hosting company says its not part of the dedicated hosting package. This is despite paying near £500 per month (approx $850) for it!

So I kinda need some kind of split function or something. However, I am going to get into a heavy discussion with our hosts as well!!!

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:tlovie
ID: 33701429
Standard edition comes with Full Text indexing, I can't remember if the default install options have it turned on, however, you just need to install it and turn it on.  I don't have much experience in it, but from what I read, it looks easy to configure, and quite robust.
0
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 668 total points
ID: 33701438
Without FULL TEXT INDEXING, search would be very slow.

Try this code which is an alternative, but not recommended on table contains more data

Raj
CREATE TABLE #table
(
	Name	VARCHAR(20)
)
INSERT INTO #table
	SELECT 'Experts Exchange' UNION
	SELECT 'Experts' UNION
	SELECT 'Exchange' UNION
	SELECT 'Experts Suggestion' UNION
	SELECT 'Exchange Offer' UNION
	SELECT 'Expert' UNION
	SELECT 'Subscription' UNION
	SELECT 'Account' UNION
	SELECT 'Question'

-- 9 records
select * from #table 

-- 6 matched records
SELECT a.* FROM #table a
	INNER JOIN (SELECT * FROM dbo.Split('Experts Exchange', ' ')) b
		on CHARINDEX(b.items, a.[Name]) > 0

DROP TABLE #table

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 33701454
Here is the split function used .
Raj
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


create FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1))        
returns @temptable TABLE (items varchar(8000))        
as        
begin        
    declare @idx int        
    declare @slice varchar(8000)        
       
    select @idx = 1        
        if len(@String)<1 or @String is null  return        
       
    while @idx!= 0        
    begin        
        set @idx = charindex(@Delimiter,@String)        
        if @idx!=0        
            set @slice = left(@String,@idx - 1)        
        else        
            set @slice = @String        
           
        if(len(@slice)>0)   
            insert into @temptable(Items) values(@slice)        
  
       set @String = right(@String,len(@String) - @idx)        
        if len(@String) = 0 break        
    end    
return        
end

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question