以下是一个存储过程的一部分: -如何在使用情况下在什么情况下使用tsql?
@ID int
@Col1 int
@Col2 int
Select *
from Table_01 t1
JOIN table_02 t2 on t1.col = t2.col
where
1 = case when @Col1 = 0 then 1 else (case when t2.Col1 = @Col1 then 1 else 0 end) end
AND 1 = case when @Col2 = 0 then 1 else (case when t2.Col2 = @Col2 then 1 else 0 end) end
AND 1 = case when @ID = 0 then 1 else (case when t2.ID = @ID then 1 else 0 end) end
目前
- 如果
@ID = 0
那么它忽略条件 - 如果@ID有值,那么它基于标准的满意度返回结果
我需要在那里添加另一个条件: -
if @ID = -1
那么应该不返回任何结果(堂妹没有匹配) 但它应该像@ID = 0
(忽略添加expresssion)
我是清楚了吗? :(
这最后一个条件是否应该胜过其他两个? – Thomas 2011-02-09 21:21:11
即使使用SQL Server 2005中的“选项(重新编译)”,这也是完全不可讨论的,据我所知。 – 2011-02-09 21:22:25