I was trying to write a statement which uses the WHERE LIKE \'%text%\' clause, but I am not receiving results when I try to use a parameter for the text. For example, this
you may try this one, used CONCAT
WHERE LastName LIKE Concat('%',@LastName,'%')
It should be:
...
WHERE LastName LIKE '%' + @LastName + '%';
Instead of:
...
WHERE LastName LIKE '%@LastName%'
The correct answer is, that, because the '%'
-sign is part of your search expression, it should be part of your VALUE, so whereever you SET @LastName
(be it from a programming language or from TSQL) you should set it to '%' + [userinput] + '%'
or, in your example:
DECLARE @LastName varchar(max)
SET @LastName = 'ning'
SELECT Employee WHERE LastName LIKE '%' + @LastName + '%'