我有一个看起来像这样的存储过程:
-- @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 * 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
谢谢你的帮助。
抢