0

Can anyone please explain why this code is not working?

ALTER function sample1 (@col VARCHAR (32), @keyWord VARCHAR (32))
RETURNS INT
AS
BEGIN
    DECLARE @res INT

    SELECT @res = COUNT(*) 
    FROM m_table 
    WHERE @col LIKE 'John Leo'

    RETURN @res
END

I noticed that when I hardcoded the column name, it works. but if I use the variable @var for it, it returns a value of 0. Is it because I placed the column name in a variable?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JanLeeYu
  • 981
  • 2
  • 9
  • 24

0 Answers0