我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[hr_SearchVacanciesAdmin]
@SearchText NVARCHAR(50) = NULL,
@CompanyName NVARCHAR(100) = NULL,
@DutyStationID INT = NULL,
@VacancyCategoryIDs VARCHAR(1000) = NULL,
@Status INT,
@Language INT = 1
BEGIN
SELECT * from table
where
deleted = 0
and status = @status
and catname = &searchtext
..
..
..
END
我想在 where 条件中添加 case 语句,以便如果 @status = 4 则不检查 delete =。我尝试关注但不工作
WHERE
1 = CASE
WHEN @Status = 4
THEN @status
WHEN dbo.hr_Vacancies.Deleted = 0
--Search Criteria
AND dbo.hr_Vacancies.Status = @Status
THEN @Status
END