存储过程返回0条记录,其中有波斯语文本
本文关键字:波斯语 文本 返回 0条 记录 存储过程 | 更新日期: 2023-09-27 18:18:15
我有一个如下所示的存储过程。当我发送一个包含波斯语字母"的参数时,它不会返回任何记录。我以前用过N,但它不起作用。
ALTER PROCEDURE [DB].[sp_Acceptor_SelectByDynamicField_ForChart]
@ProjectType NVARCHAR(50)=NULL,
@FromDate datetime=NULL,
@ToDate datetime=NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Where VARCHAR(MAX),
@SQL VARCHAR(MAX)
SET @Where = ' WHERE 1=1 '
IF ( @ProjectType IS NOT NULL )
SET @Where = @Where + ' AND ProjectType = N''' + @ProjectType + ''' '
IF ( @FromDate IS NOT NULL AND @ToDate IS NOT NULL )
SET @Where = @Where + ' AND PmDate BETWEEN ''' + CONVERT(nvarchar(50),(@FromDate),101) + ''' AND ''' + CONVERT(nvarchar(50),@ToDate, 101) + ''' '
SET @SQL = 'SELECT * From Acceptor ' + @Where
EXEC (@SQL)
END
不确定这是否会解决您所询问的问题,但是有一种更好的方法来编写这个存储过程。因此,您的存储过程很容易受到SQL注入攻击。试试这个:
ALTER PROCEDURE [itnarenj.ir_DB].[sp_Acceptor_SelectByDynamicField_ForChart]
@ProjectType NVARCHAR(50)=NULL,
@FromDate datetime=NULL,
@ToDate datetime=NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM Acceptor
WHERE (ProjectType = @ProjectType OR @ProjectType IS NULL)
AND (
@FromDate IS NULL OR @ToDate IS NULL
OR
(
PmDate >= @FromDate
AND PmDate <= @ToDate
)
)
END