我试图编写一个存储过程,我想通过 IF/Else 语句测试传入的参数的某个值,并最终将结果与另一个表相交。类似于以下内容的非工作伪示例。
ALTER PROCEDURE [dbo].[Search]
@Keyword nvarchar(MAX),
@ClasificationId int
AS
BEGIN
SET NOCOUNT ON;
IF (@Keyword != null)
SELECT * FROM Table WHERE [Keyword] LIKE @Keyword
ELSE
SELECT * FROM Table
INTERSECT
IF (@Classification != null)
SELECT * FROM Table WHERE [ClassificationID] = @ClassificationId
ELSE
SELECT * FROM Table
END