SELECT
CAST((Discount_Amount AS numeric(11,2))/1.14)*0.14 AS [Service Tax]
FROM APDEPADV
答案 0 :(得分:2)
我认为你的括号在错误的地方:
SELECT
(CAST(Discount_Amount AS numeric(11,2))/1.14)*0.14 AS [Service Tax]
FROM APDEPADV
您应首先投射Discount_Amount
,然后执行其他计算:
如果你稍微破解你的代码,你可能会理解发生了什么:
CAST
具有以下语法:CAST(a AS b)
CAST((Discount_Amount AS numeric(11,2))/1.14)
CAST
函数,所以整个表达式(Discount_Amount AS numeric(11,2))/1.14
被视为你想要投射的值(a
1以上)。这会产生一些后果。首先,CAST(a AS b)
现在变为CAST(a)
,这没有多大意义(你将它投射到什么地方?)
其次,这意味着表达式Discount_Amount AS numeric(11,2)
正在与CAST
函数分开处理。像Discount_Amount/1.14
这样的东西是一个有效的表达式,但(Discount_Amount AS numeric(11,2))/1.14
本身不是,这就是你收到错误的原因。
通过重新排列括号,您应该更接近您的意图:
SELECT
(
CAST(Discount_Amount AS numeric(11,2))
/1.14
)
* 0.14
AS [Service Tax]
FROM APDEPADV
答案 1 :(得分:0)
试试这个
SELECT
(CAST(Discount_Amount AS numeric(11,2))/1.14)*0.14 AS [Service Tax]
FROM APDEPADV
答案 2 :(得分:0)
括号的顺序是错误的。理解表达式,然后相应地重写括号。
SELECT
((Cast(Discount_Amount AS numeric(11,2))/1.14)*0.14 AS [Service Tax]
FROM APDEPADV