请教:带case when的check约束怎么写
a表
returnflag=1时,验证amount=isnull(quantity,0)*isnull(realprice,0)
returnflag=0时,验证costamount=isnull(quantity,0)*isnull(costprice,0)
ALTER TABLE a
ADD CHECK
(returnflag IN('0','1') and case returnflag when 0 then costamount=isnull(quantity,0)*isnull(costprice,0) when 1 then amount=isnull(quantity,0)*isnull(realprice,0) end )
这样写提示我:第 4 行: '=' 附近有语法错误。
[解决办法]
ALTER TABLE aADD CHECK ( (returnflag=0 and costamount=isnull(quantity,0)*isnull(costprice,0)) or (returnflag=1 and amount=isnull(quantity,0)*isnull(realprice,0)))
[解决办法]