抱歉创建一个新线程。我无法在上一个帖子中正确地提出问题。
我在 SQL Server 2008 中有一个如下所示的表 -
Id Status
--------------
1 A
2 I
3 NULL
@Status
我有一个作为参数的存储过程。
If the @Status is "-1", I need to retrieve records 1, 2.
If the @Status is "A", I need to retrieve only record 1.
If the @Status is "I", I need to retrieve only record 2.
我希望能够在SELECT
不使用IF ELSE
. SELECT 语句中有很多连接和东西,我不想在 ELSE 条件中重复同样的事情。
我尝试了以下但得到不正确的数据 -
SELECT * FROM Person WHERE Status = @Status OR @Status IS NOT NULL
select * from Person
where (@Status is not null and Status = @Status) or
(@Status is null and Status in ('A', 'P'))