T-SQL 和 WHERE LIKE %Parameter% 子句 [英] T-SQL and the WHERE LIKE %Parameter% clause
本文介绍了T-SQL 和 WHERE LIKE %Parameter% 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图编写一个使用 WHERE LIKE '%text%' 子句的语句,但是当我尝试使用文本参数时没有收到结果.例如,这有效:
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%'
这将返回用户 Flenning、Manning、Ningle 等.但此语句不会:
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.
推荐答案
应该是:
...
WHERE LastName LIKE '%' + @LastName + '%';
代替:
...
WHERE LastName LIKE '%@LastName%'
这篇关于T-SQL 和 WHERE LIKE %Parameter% 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文