我有一个带有CASE子句的update子句,例如:
UPDATE [D]
SET
[DesignTypeGuid] = (CASE
WHEN([D].[DesignNumber] < @CurrentContractedDesignNumber)
THEN @BDTypeGuid
ELSE @COTypeGuid
END)
我的问题是我该如何添加第三个条件,我的意思是我也想做
[D].[DesignNumber] = @CurrentContractedDesignNumber THEN @CDTypeGuid
是否可以将其合并到现有案例中?
答案 0 :(得分:4)
这是你的意思吗?
SET [DesignTypeGuid] = (CASE WHEN [D].[DesignNumber] < @CurrentContractedDesignNumber
THEN @BDTypeGuid
WHEN [D].[DesignNumber] = @CurrentContractedDesignNumber
THEN @CDTypeGuid
ELSE @COTypeGuid
END)
答案 1 :(得分:4)
只需在
时添加另一个UPDATE [D]
SET [DesignTypeGuid] = (CASE
WHEN [D].[DesignNumber] < @CurrentContractedDesignNumber
THEN @BDTypeGuid
WHEN [D].[DesignNumber] = @CurrentContractedDesignNumber T
HEN @CDTypeGuid
ELSE @COTypeGuid
END)
答案 2 :(得分:1)
在WHEN . .
表达式中添加其他CASE
:
(CASE WHEN [D].[DesignNumber] < @CurrentContractedDesignNumber
THEN @BDTypeGuid
WHEN [D].[DesignNumber] = @CurrentContractedDesignNumber
THEN @CDTypeGuid
ELSE @COTypeGuid
END)