我正在尝试构建替换语句但我收到此错误:
替换功能需要3个参数。
关键字'附近有'的语法不正确。如果此语句是公用表表达式,xmlnamespaces子句或更改跟踪上下文子句,则必须以分号结束前一个语句。
SQl脚本:
select ccc.*,
replace(replace(replace(replace(replace(bbb.Text,
'[Change]',convert(varchar,CAST(coalesce(ccc.change,0) as decimal(10,2)))),
'[CurrentAmount]','$'+convert(varchar,CAST(coalesce(ccc.currentamount,0) as money),1),
'[Increase]',convert(varchar,CAST(coalesce(ccc.increase,0) as decimal(10,2))))+ '%',
'[AmountIncrease]',convert(varchar,CAST(coalesce(ccc.amountincrease,0) as decimal(10,2))))+ '%',
'[AmountDecrease]',convert(varchar,CAST(coalesce(ccc.amountdecrease,0) as decimal(10,2))))+ '%'
) Condition
from CCCCheck ccc with (NOLOCK)
inner join BBBCheck bbb with (NOLOCK)on...
答案 0 :(得分:0)
在括号前的最后一次替换结尾处有一个额外的逗号:
'[AmountDecrease]',convert(varchar,CAST(coalesce(ccc.amountdecrease,0) as decimal(10,2))))+ '%',
) Condition
看起来你可能也在增加替换附近的中间错过了一个REPLACE:
SELECT ccc.*
, REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(bbb.Text, '[Change]', CONVERT(VARCHAR, CAST(COALESCE(ccc.change, 0) AS DECIMAL(10, 2)))
), '[CurrentAmount]', '$' + CONVERT(VARCHAR, CAST(COALESCE(ccc.currentamount, 0) AS MONEY), 1), '[Increase]', CONVERT(VARCHAR, CAST(COALESCE(ccc.increase, 0) AS DECIMAL(10, 2)))
) + '%', '[AmountIncrease]', CONVERT(VARCHAR, CAST(COALESCE(ccc.amountincrease, 0) AS DECIMAL(10, 2)))
) + '%', '[AmountDecrease]', CONVERT(VARCHAR, CAST(COALESCE(ccc.amountdecrease, 0) AS DECIMAL(10, 2)))
) + '%'
) Condition
FROM CCCCheck ccc WITH (NOLOCK)
答案 1 :(得分:0)
这样有三个地方:)))) + '%'
将最后一个括号移到:))) + '%')
答案 2 :(得分:0)
我有一个额外的括号,我想
convert(varchar,
CAST(coalesce(ccc.amountincrease,
0
) as decimal(10,2)
)
))+ '%'
最后一个括号是一个额外的括号。
它应该成为
convert(varchar,
CAST(coalesce(ccc.amountincrease,
0
) as decimal(10,2)
)
)+ '%'
答案 3 :(得分:0)
SELECT ccc.*,
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(bbb.Text,
'[Change]', CONVERT(varchar, CAST(COALESCE(ccc.change, 0) AS decimal(10, 2)))),
'[CurrentAmount]', '$' + CONVERT(varchar, CAST(COALESCE(ccc.currentamount, 0) AS money), 1)),
'[Increase]', CONVERT(varchar, CAST(COALESCE(ccc.increase, 0) AS decimal(10, 2))) + '%'),
'[AmountIncrease]', CONVERT(varchar, CAST(COALESCE(ccc.amountincrease, 0) AS decimal(10, 2))) + '%'),
'[AmountDecrease]', CONVERT(varchar, CAST(COALESCE(ccc.amountdecrease, 0) AS decimal(10, 2))) + '%')
as Condition FROM CCCCheck ccc WITH (NOLOCK)