Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 我如何在何处添加like_Sql_Stored Procedures - Fatal编程技术网

Sql 我如何在何处添加like

Sql 我如何在何处添加like,sql,stored-procedures,Sql,Stored Procedures,我需要在存储过程SQLServer中使用like-in-where条件 我尝试了以下代码,但在@product\u name\u id上显示错误 我犯错误的地方…有人能帮我吗 @product_name_id varchar(50) as begin select Product_Name as [Product Name], Product_Id as [Product Id] from tb_new_product_Name_id where Product_Name

我需要在存储过程SQLServer中使用like-in-where条件

我尝试了以下代码,但在
@product\u name\u id
上显示错误

我犯错误的地方…有人能帮我吗

@product_name_id varchar(50)

as 
begin 
select Product_Name as [Product Name], Product_Id as [Product Id] from  
    tb_new_product_Name_id  where  Product_Name LIKE %@product_name_id% or Product_Id 
    like %@product_name_id%

end
在其周围放置
''

...
where Product_Name LIKE '%' + @product_name_id + '%' 
   or Product_Id   LIKE '%' + @product_name_id + '%';
在其周围放置
''

...
where Product_Name LIKE '%' + @product_name_id + '%' 
   or Product_Id   LIKE '%' + @product_name_id + '%';
尝试以下操作:为SQL中的字符串添加“”

select Product_Name as [Product Name], Product_Id as [Product Id] from  
tb_new_product_Name_id  where  Product_Name LIKE '%'+@product_name_id+'%' or Product_Id 
like '%'+@product_name_id+'%'
尝试以下操作:为SQL中的字符串添加“”

select Product_Name as [Product Name], Product_Id as [Product Id] from  
tb_new_product_Name_id  where  Product_Name LIKE '%'+@product_name_id+'%' or Product_Id 
like '%'+@product_name_id+'%'

这是行不通的,因为您将
@product\u name\u id
粘贴到字符串中。@很高兴我认为这不会给您带来错误。因为对于like运算符,我们使用的是从姓名为“%Vaibh%”的人中选择姓名,所以我将字符串连接起来。这是行不通的,因为您将
@product\u name\u id
粘贴到字符串中。@Happy我不这么认为给出u错误。因为对于like运算符,我们使用select name from Person,其中的名称类似“%Vaibh%”,所以我连接字符串。