Solved

keyword search in stored procedure

Posted on 2009-05-17
3
231 Views
Last Modified: 2012-05-07
We need a stored procedure that list tall he recordset with a given column containing specified keywords (please not the s:).
For example, MyTable contains the column MyMemo, and we need all the recordsets having 'john' AND 'eat' keywords. Keyword can be passed to the stored procedure thru a string like 'john,eat' with a given separator or thru xml format so we can use some request "from @xmlkeywords.nodes" stuff.
Thanks for help








0
Comment
Question by:javilmer
3 Comments
 
LVL 5

Expert Comment

by:Aanvik
ID: 24406279
Try this.
declare @newString varchar(205)
Set @newString = '%Test%'
-- Insert statements for procedure here
select so.name from sysobjects so join syscomments sc on so.id = sc.id 
where sc.text like @newString
order by name

Open in new window

0
 

Author Comment

by:javilmer
ID: 24406580
I dont' think it will work with more than one keywords...
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 24408474
you can do this:

declare @x xml, @newx varchar(1000)
set @x = '<search><val>john</val><val>eat</val></search>'

select * from tablename g
where exists(
select 1
from @x.nodes('/search/val') t(c)
where g.mymemo like '%' + c.value('.', 'varchar(100)')  + '%')
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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