转换和求和错误

时间:2014-07-16 14:44:12

标签: sql sql-server

我收到一条错误消息,指出从十进制(9,1)到十进制(7,4)转换时可能会发生数据丢失。 sum(b.Column2...)行发生此错误。

    insert into @tempTable
    select a.Column1, sum(b.Column2 * c.Column3 * d.Column4)
    from dbo.Table1 as a
    join dbo.Table2 as b on specified columns
    join dbo.Table3 as c on specified columns
    join dbo.Table4 as d on specified columns

我尝试了以下内容:

    insert into @tempTable
    select a.Column1, cast(sum(b.Column2 * c.Column3 * d.Column4) as decimal (7,4))
    from dbo.Table1 as a
    join dbo.Table2 as b on specified columns
    join dbo.Table3 as c on specified columns
    join dbo.Table4 as d on specified columns

我也尝试过:

   declare @tempColumn2 decimal(7,4);

   select @tempColumn2 = cast(a.Column1 as decimal(7,4)) -- This gives me an unresolved error message.

    insert into @tempTable
    select a.Column1, sum(@tempColumn2 * c.Column3 * d.Column4)
    from dbo.Table1 as a
    join dbo.Table2 as b on specified columns
    join dbo.Table3 as c on specified columns
    join dbo.Table4 as d on specified columns

任何提示将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:1)

您收到错误消息是因为您试图将范围{-999999999.9 .. 999999999.9}压缩到{-999.9999 .. 999.9999}

“如何将十进制(9,1)拟合为十进制(7,4)”的答案?“是:你没有。