本文介绍了如何在存储过程中搜索nvarchar文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在我的存储过程中搜索nvarchar文本。要搜索的nvarchar文本作为参数传递。 虚拟表 DECLARE @tb TABLE(Id INT,名称NVARCHAR(100)); 插入@tb VALUES(1,'Aman'); 插入@tb VALUES(2,N'سانديب'); 插入@tb VALUES(3,'Anuj'); 插入@tb VALUES(4,N'فيكاس'); 插入@tb VALUES(5,N'اليت'); 插入@tb VALUES(6,'Sunil'); 插入@tb VALUES( 7,'Ajay'); 插入@tb VALUES(8,N'فيشال'); 插入@tb VALUES(9,'Tarun'); - 选择*来自@tb DECLARE @str NVARCHAR(50)= N'سانديب' SELECT * FROM @tb WHERE名称喜欢'%'+ @str +'%' - 工作正常 我知道我们需要在N'前面搜索nvarchar文本。但是如何将这个参数添加到存储过程中 我尝试过: DECLARE @ str1 NVARCHAR(50)='سانديب' SELECT * FROM @tb WHERE Name LIKE'%'+ @ str1 +'%' 它不工作 DECLARE @ str2 NVARCHAR(50)='سانديب'; SELECT * FROM @tb WHERE名称LIKE'%'+ N''+ @ str2 +'%' 它仍无法正常工作解决尝试这个 创建 PROCEDURE SEARCHTEXT - 添加此处存储过程的参数 @ TEXT NVARCHAR ( 50 ) AS BEGIN DECLARE @ str1 NVARCHAR ( 50 ) SET @ str1 = N ' ' + @ TEXT SELECT * FROM @ tb WHERE 名称 LIKE ' %' + @ str1 + ' %' 尝试: DECLARE @ str1 NVARCHAR ( 50 )= N ' سانديب' - - 在此处添加缺少的N前缀 SELECT * FROM @ tb WHERE 名称 LIKE N ' %' + @ str1 + N ' %' - 此处有两个%字符串 I am searching nvarchar text in my stored procedure. nvarchar text to be searched is passed as parameter. dummy tableDECLARE @tb TABLE (Id INT, Name NVARCHAR(100));insert into @tb VALUES (1,'Aman');insert into @tb VALUES (2,N'سانديب');insert into @tb VALUES (3,'Anuj');insert into @tb VALUES (4,N'فيكاس');insert into @tb VALUES (5,N'اليت');insert into @tb VALUES (6,'Sunil');insert into @tb VALUES (7,'Ajay');insert into @tb VALUES (8,N'فيشال');insert into @tb VALUES (9,'Tarun');--select * from @tbDECLARE @str NVARCHAR(50)=N'سانديب'SELECT * FROM @tb WHERE Name LIKE '%'+ @str +'%'--It is working fineI know we need to prefix N' to search nvarchar text. But how can i add this in parameter to stored procedureWhat I have tried:DECLARE @str1 NVARCHAR(50)='سانديب'SELECT * FROM @tb WHERE Name LIKE '%'+ @str1 +'%'it is not workingDECLARE @str2 NVARCHAR(50)='سانديب';SELECT * FROM @tb WHERE Name LIKE '%' + N'' + @str2 + '%' it is still not working 解决方案 Try thisCREATE PROCEDURE SEARCHTEXT -- Add the parameters for the stored procedure here @TEXT NVARCHAR(50)ASBEGINDECLARE @str1 NVARCHAR(50)SET @str1=N'' + @TEXT SELECT * FROM @tb WHERE Name LIKE '%'+ @str1 +'%'Try: DECLARE @str1 NVARCHAR(50) = N'سانديب' -- Add the missing "N" prefix hereSELECT * FROM @tb WHERE Name LIKE N'%'+ @str1 + N'%' -- And to the two "%" strings here 这篇关于如何在存储过程中搜索nvarchar文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-17 00:57