Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 A simple search

Author  Topic 

Apples
Posting Yak Master

146 Posts

Posted - 2008-03-24 : 12:30:51
I have a table of articles:

-------------------------------------
Articles
-------------------------------------
ID | Date | Headline | Body
-------------------------------------

I'm trying to write a stored procedure that will search for a given keyword. Here's what I have:

CREATE PROCEDURE sproc_SearchArticles
(
@keyword varchar(50)
)
AS
SELECT ID, Date, Headline, Body
FROM Articles
WHERE Body LIKE %@keyword%
ORDER BY Date DESC
RETURN


That keeps giving me an error. If I put quotes around it, it will literally look for the term @keyword anywhere in the body.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-24 : 12:41:38
[code]WHERE Body LIKE '%' + @keyword + '%'[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -