2

here's my stored procedure.

ALTER PROCEDURE [dbo].[SearchIngredients] 
    @Term NVARCHAR(50) 
AS
BEGIN
    SET NOCOUNT ON;

    SELECT  *
    FROM    dbo.FoodAbbrev
    WHERE   Name LIKE '%@Term%'
    ORDER BY Name

END

I kept getting no result back. I think its because I put the varaible in the single quote and probably DB thinks that is part of string, not a variable. tried a few other ways, still cannot fix it, please help me.

I also tried. still get nothing back.

    SET @Term = '''%' + @Term + '%'''

    SELECT  *
    FROM    dbo.FoodAbbrev
    WHERE   Name LIKE @Term
    ORDER BY Name
qinking126
  • 11,385
  • 25
  • 74
  • 124

2 Answers2

6

Simply;

set @Term = '%' + @Term + '%'

Your just adding 2 constant strings to a variable.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

Correct way is below:

set @FieldValue = '''' + @FieldValue + ''''
Jens Erat
  • 37,523
  • 16
  • 80
  • 96
Kavit Trivedi
  • 129
  • 3
  • 13