У меня есть хранимая процедура, которая будет иметь 3 параметра. Я хочу проверить каждую комбинацию Null / Not Null, но вместо того, чтобы выписывать 16 различных операторов Select с помощью Else. Вот мой пример в настоящее время ...
...
ELSE IF @team IS NOT NULL AND
@position IS NULL AND
@filter IS NOT NULL
BEGIN
SELECT P1.PlayerKey, P1.Player, P2.Position, P1.Height, P1.Weight, P1.Speed, P1.Status
FROM Player AS P1
INNER JOIN Position AS P2 ON P1.PositionID = P2.PositionID
INNER JOIN Team AS T1 ON T1.TeamID = P1.TeamID
WHERE P1.TeamID = @team AND P1.Player LIKE '%' + @filter + '%'
ORDER BY P2.PosSort;
END
ELSE IF @team IS NULL AND
@position IS NOT NULL AND
@filter IS NOT NULL
BEGIN
SELECT P1.PlayerKey, P1.Player, P2.Position, P1.Height, P1.Weight, P1.Speed, P1.Status
FROM Player AS P1
INNER JOIN Position AS P2 ON P1.PositionID = P2.PositionID
INNER JOIN Team AS T1 ON T1.TeamID = P1.TeamID
WHERE P2.Position = @position AND P1.Player LIKE '%' + @filter + '%'
ORDER BY P2.PosSort;
END
ELSE IF @team IS NOT NULL AND
@position IS NULL AND
@filter IS NOT NULL
BEGIN
SELECT P1.PlayerKey, P1.Player, P2.Position, P1.Height, P1.Weight, P1.Speed, P1.Status
FROM Player AS P1
INNER JOIN Position AS P2 ON P1.PositionID = P2.PositionID
INNER JOIN Team AS T1 ON T1.TeamID = P1.TeamID
WHERE P1.TeamID = @team AND P1.Player LIKE '%' + @filter + '%'
ORDER BY P2.PosSort;
END
...