【发布时间】:2014-08-21 21:40:49
【问题描述】:
有类似这样的存储过程。
CREATE PROCEDURE test
@ID
@inventory bit = 0
@status nvarchar(2) = null
AS
BEGIN
SELECT
ID
INVENTORY = (SELECT SUM(Inventory) FROM Option WHERE /*Inventory if 0 with if 1 without*/)
STATUS
WHERE
--TODO Status if
END
status 可以是null, '', 'preordered' 时如何创建 if 语句 例如:如果null 选择所有状态,如果'' 选择空状态,如果某些状态 - 选择某些状态。并且需要为 Inventory(with/without) 创建 where 条件
【问题讨论】:
-
看看前几天的这个问题:stackoverflow.com/questions/25414333/…
标签: sql-server tsql stored-procedures if-statement optional-parameters