我有一個存儲過程,看起來像:if語句的WHERE子句
-- @intUserType int (Passed in from sproc)
IF @intUserType = 1
BEGIN
SELECT * FROM Users
WHERE Users.isDeleted = 0
END
IF @intUserType = 4
BEGIN
SELECT * FROM Users
WHERE Users.isDeleted = 0
AND Users.UserType <> 1
END
IF @intUserType = 3
BEGIN
SELECT * FROM Users
WHERE Users.isDeleted = 0
AND Users.UserType IN (1,3,4)
END
我想縮短它,而不是使用這麼多的SELECT語句,有點像:
SELECT * FROM Users
WHERE Users.isDeleted = 1
AND
IF @intUserType = 1
THEN Users.UserType > 0
ELSE IF @intUserType = 4
THEN Users.UserType <> 1
ELSE IF @intUserType = 3
THEN Users.UserType NOT IN(1,3,4)
END
END
感謝您的任何幫幫我。
羅布
謝謝,這很好用! – Robert