Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax problem

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
I am using the below code but want to have the searchterm do:

name like '%@searchterm%'

but can't get the syntax to work

--Create a temporary table
CREATE TABLE #TempItems
(
ID int IDENTITY,
Name varchar(250),
PID int
)

-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Name, pid)
SELECT Name,id FROM courses WHERE name = @searchterm ORDER BY name
 
Hiya,

If you want to use the name like '%@searchterm%' then you need to have the % within the value @searchterm, so that you build it:

SELECT @searchterm = '%'
SELECT @searchterm = @searchterm + 'blah blah blah'
SELECT @searchterm = @searchterm + '%'

Then you can do

WHERE name LIKE @searchterm

That will work correctly

HTH

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top