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
  • 704,970
  • 168
  • 1,303
  • 1,425
JanLeeYu
  • 996
  • 2
  • 9
  • 22

0 Answers0