我如何避免的if/else嗎?表中的「活動」列不能爲空。帶有空位的SQL Server 2008 sp arg:如何避免if/else選擇?
CREATE procedure spExample(@bitActive bit)
as
if @bitActive is not null
select a.PKID
from Alerts a
where a.Active = @bitActive
else
select a.PKID
from Alerts a
在SQL Server 2008上,'OPTION(RECOMPILE)'可以幫助'@bitActive IS NULL OR a.Active = @ bitActive'模式,但不能'ISNULL(@bitActive,a.Active)= a.Active' [正如這裏討論的](http://www.sommarskog.se/dyn-search-2008.html) –