我在它的语句中创建了一个动态WHERE
子句它已成功创建,但我得到的输出为 0。有什么想法我错了吗?SELECT
Stored Procedure
SQL SERVER 2008-R2.
这是我的SP:
CREATE PROCEDURE [dbo].[SPData]
@Id int = NULL,
@Requester varchar(20) = NULL,
@Suggester varchar(20) = NULL
AS
BEGIN
DECLARE @sql nvarchar(4000)
SELECT @sql=' [Id], [Suggester], [Requester] from CRM.dbo.Request_Table WHERE 1=1 '
If (@Id) IS NOT NULL
SELECT @sql=@sql + ' AND Id=(@Id) '
If (@Suggester) IS NOT NULL
SELECT @sql=@sql + ' AND Suggester like (@Suggester) '
If (@Requester) IS NOT NULL
SELECT @sql=@sql + ' AND Requester like (@Requester) '
END
GO