十进制列的SQL Sum函数返回int而不是decimal

十进制列的SQL Sum函数返回int而不是decimal,sql,sql-server,tsql,Sql,Sql Server,Tsql,我有一个十进制类型的列,我需要对其使用sum函数,如下所示: declare @credit decimal = (select ( select ISNULL(SUM(Convert(DECIMAL(13,2), Amount)),0) from TransactionDetail as t1

我有一个十进制类型的列,我需要对其使用sum函数,如下所示:

   declare @credit decimal = (select
                               (    select ISNULL(SUM(Convert(DECIMAL(13,2), Amount)),0)
                                    from TransactionDetail as t1
                                    where t1.AccountFrom = @fromAccount and t1.AccountTo = @toAccount
                               ) -     
                               (    select ISNULL(SUM(Convert(DECIMAL(13,2),Amount)),0)
                                    from TransactionDetail as t1
                                    where t1.AccountFrom = @toAccount  and t1.AccountTo = @fromAccount
                               ) 
                           )
select @credit
输出应为十进制数,如: 13.56


但是,结果总是int,有什么建议吗

默认的
scale
为0。如果要将结果作为特定格式,请尝试显式向变量添加精度和比例:

declare @credit decimal(13, 2) = (select . . .
这种行为很好:

将存储在列表右侧的小数位数 小数点。该数字从p中减去,以确定 小数点左侧的最大位数。最大值 可存储在屏幕右侧的小数位数 小数点。比例必须是从0到p的值。cSale可以是 仅当指定了精度时才指定默认比例为0


我错过了,非常感谢