-2
SELECT LIFNR,
 SUM(CASE WHEN  UPPER([WAERS])='USD' THEN ROUND(CONVERT(numeric(10,2),DMBTR)* (-1),2)
               WHEN UPPER(WAERS)='USD' THEN ROUND(CONVERT(numeric(10,2),DMBTR),2) 
               ELSE ROUND(CONVERT(numeric(10,2),DMBTR),2)
               END)
AS 'AMOUNT'
FROM tbl_BSAK
GROUP BY LIFNR;

大家好。

我刚刚编写了一段代码,但我不断收到错误消息“将数据类型 varchar 转换为数字时出错。” 我确定这很简单,但是我花了太多时间进行故障排除...

请帮帮我!!!!非常感谢!!!

4

1 回答 1

4

根据语法,我假设这是 SQL Server。

如果要查找违规值,请执行以下操作:

select *
FROM tbl_BSAK
where isnumeric(DMBTR) = 0 and DMBTR is not null;

要解决此问题,请执行以下操作:

SELECT LIFNR,
 SUM(CASE WHEN isnumeric(DMBTR) = 1and UPPER([WAERS])='USD' THEN ROUND(CONVERT(numeric(10,2),DMBTR)* (-1),2)
               WHEN isnumeric(DMBTR) = 1 and UPPER(WAERS)='USD' THEN ROUND(CONVERT(numeric(10,2),DMBTR),2) 
               when isnumeric(DMBTR) = 1 then ROUND(CONVERT(numeric(10,2),DMBTR),2)
               END)
AS 'AMOUNT'
FROM tbl_BSAK
GROUP BY LIFNR;
于 2013-05-30T21:08:33.930 回答