SQL案例语句案例计算
我的案例语句默认为默认零结果,而不管两个条件如何。我不确定问题是什么。
,CASE
WHEN [Contract]='INIM' THEN 'Index'
WHEN [Contract]='BANK' THEN 'Index'
ELSE 'Single'
END AS 'I/S'
,CASE
WHEN 'I/S'='Index' THEN ([Quantity] *[Spot Price]*10)/1000000
WHEN 'I/S'='Single' THEN ([Quantity] *[Spot Price]*100)/1000000
ELSE 0
END AS [Notional (ZARm)]
My CASE statement defaults to default zero result regardless of the two conditions. I am not sure what the problem is.
,CASE
WHEN [Contract]='INIM' THEN 'Index'
WHEN [Contract]='BANK' THEN 'Index'
ELSE 'Single'
END AS 'I/S'
,CASE
WHEN 'I/S'='Index' THEN ([Quantity] *[Spot Price]*10)/1000000
WHEN 'I/S'='Single' THEN ([Quantity] *[Spot Price]*100)/1000000
ELSE 0
END AS [Notional (ZARm)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
值
'i/s'
是字符串文字,而不是别名i/s
。无论如何,不可能在相同的选择
中重复使用此别名。这是一个更正的版本:请注意,基于第一个
案例
表达式,else 0
case> case 表达式永远不会发生。The value
'I/S'
is a string literal, and not the aliasI/S
. In any case, it is not possible to reuse this alias in the sameSELECT
. Here is a corrected version:Note that, based on the first
CASE
expression, theELSE 0
of the secondCASE
expression will never occur.