简体   繁体   English

MsSql:如何在“LIKE”运算符的查询中传递参数而不是静态值

[英]MsSql: How to pass a parameter in query in the 'LIKE' Operator instead of a static value

How can I pass a parameter in query instead of static value in the LIKE operator?如何在查询中传递参数而不是 LIKE 运算符中的静态值?

My table would be like this我的桌子是这样的

The query i am currently using is:我目前使用的查询是:

Select  Url from UrlTable where Url LIKE  '%customer%' ;

You can use variables to assign values to them. 您可以使用变量为它们分配值。 Passing then into a stored procedure is a common process and the syntax is below. 然后将其传递到存储过程是一个常见过程,语法如下。

CREATE PROCEDURE Test(@Customer NVARCHAR(150))
AS
    Select  Url from UrlTable where Url LIKE  '%'+@Customer+'%'

您可以在oracle中使用如下查询

Select  Url from UrlTable where Url LIKE  '%' || :customer || '%'; 

Can you try the following; 您可以尝试以下方法吗?

DECLARE @Customer nvarchar(50) = [value_to_filter];

Select  Url from UrlTable where Url LIKE  '%' + @customer + '%'; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM