【发布时间】:2014-01-29 21:39:57
【问题描述】:
我正在尝试将NVARCHAR 参数传递给我的存储过程。存储过程应该找到所有符合指定条件的供应商。我唯一的问题是我试图通过包含希伯来语的标准。
ALTER PROCEDURE [dbo].[FindSupplier]
-- Add the parameters for the stored procedure here
@search_criteria nvarchar(100) = ''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @hebrew as bit = 0
IF @search_criteria LIKE '%[אבגדהוזחטיחכךילמנפףערקשת]%'
BEGIN
SET @hebrew = 1
END
IF @hebrew = 0
BEGIN
SELECT comn020.t_suno 'Supplier Code'
, hebcom020.t_nama 'Supplier Name1'
, hebcom020.t_namb 'Supplier Name2'
FROM com020 WITH (NOLOCK)
INNER JOIN hebcom020 WITH (NOLOCK)
ON hebcom020.t_suno = com020.t_suno
WHERE (LTRIM(RTRIM(com020.t_suno)) LIKE N'%' + @search_criteria + '%')
OR (SOUNDEX(LTRIM(RTRIM(com020.t_suno))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')
OR (LTRIM(RTRIM(hebcom020.t_nama)) LIKE N'%' + @search_criteria + '%')
OR (SOUNDEX(LTRIM(RTRIM(hebcom020.t_nama))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')
OR (LTRIM(RTRIM(hebcom020.t_namb)) LIKE N'%' + @search_criteria + '%')
OR (SOUNDEX(LTRIM(RTRIM(hebcom020.t_namb))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')
END
ELSE /* hebrew */
BEGIN
SELECT com020.t_suno 'Supplier Code'
, hebcom020.t_nama 'Supplier Name1'
, hebcom020.t_namb 'Supplier Name2'
FROM com020 WITH (NOLOCK)
INNER hebcom020 WITH (NOLOCK)
ON hebcom020.t_suno = com020.t_suno
WHERE hebcom020.t_nama Collate Hebrew_CI_AI LIKE N'%' + @search_criteria + '%' Collate Hebrew_CI_AI
OR (LTRIM(RTRIM(hebcom020.t_namb)) LIKE N'%' + @search_criteria + '%')
END
END
当我尝试传递 exec FindSupplier 'ב' 之类的内容时,SQL 服务器将 char 'ב' 识别为 '?'
我们将非常感谢您的帮助
UPD:exec FindSupplier N'ב' 工作
UPD2:在 Visual Studio 中需要使用以下字符串运行 sp
="exec FindSupplier N'" & Parameters!search_criteria.Value & "'"
【问题讨论】:
-
这是一个相关的问题...stackoverflow.com/questions/3438483/…
-
Jason,情况不一样...我需要处理sp参数,而不是声明变量
-
这不起作用? exec FindSupplier N'ב'
-
实际上它确实有效,谢谢! (这是我的错误)。搞定了
-
@IgorM 如果您发布问题,然后在任何人回答之前弄清楚,那么您应该发布答案以帮助可能遇到相同问题的其他人。谢谢:)
标签: sql-server tsql stored-procedures unicode hebrew