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 works:
SELECT Employee WHERE LastName LIKE '%ning%'
This would return users Flenning, Manning, Ningle, etc. But this statement would not:
DECLARE @LastName varchar(max) SET @LastName = 'ning' SELECT Employee WHERE LastName LIKE '%@LastName%'
No results found. Any suggestions? Thanks in advance.
Create a select query, and then open the query in Design view. In the Criteria row of the field you want to add a parameter to, type Like "*"&[, the text that you want to use as a prompt, and then ]&"*".
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
Not only LIKE, but you can also use multiple NOT LIKE conditions in SQL. You will get records of matching/non-matching characters with the LIKE – this you can achieve by percentile (%) wildcard character. Below use cases, help you know how to use single and multiple like conditions.
It should be:
... WHERE LastName LIKE '%' + @LastName + '%';
Instead of:
... WHERE LastName LIKE '%@LastName%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With