如何在SQL中使用带参数的'LIKE'语句?这是我到目前为止所做的:
ALTER proc [dbo].[select_user_by_adress]
@user_adress nvarchar(max)
as
begin
select *
from dbo.a_user_table
where user_adress like '%'+ @user_adress +'%'
end
答案 0 :(得分:1)
构建动态SQL然后执行。请注意所需的额外引号作为转义字符。
ALTER proc [dbo].[select_user_by_adress]
@user_adress nvarchar(max)
as
begin
declare @sql varchar(max)
@sql = 'select * from dbo.a_user_table where user_adress like ''%' + @user_adress +'%'''
execute (@sql)
end