记录一次Mybatis整合SqlServer时,结果集封装错误,

场景:用户消费,
->扣用户的账户余额,将用户扣款前的余额,扣款后的余额返回
SQL:update ‘用户’ set
‘余额’=‘余额’-#{消费金额}
OUTPUT DELETED.‘余额’ as [befAmtMoney] ,
Inserted.‘余额’ as [aftAmtMoney]
where Decid=#{decid}
执行结果:数据库结果一些正常,但是Mybatis用BigDecimal接收到两个值的 befAmtMoney-aftAmtMoney 不等于 消费金额;
解决办法:
update ic set
cje = Convert(decimal(18,2),cje) - Convert(decimal(18,2),#{jkje}) ,jcs = jcs+1
OUTPUT Convert(decimal(18,2),DELETED.cje) as [befAmtMoney] , Convert(decimal(18,2),Inserted.cje) as [aftAmtMoney]
where Decid=#{decid};
将更新余额都加上Convert(decimal(18,2),“金额”);

你可能感兴趣的:(数据库)