日期:2014-05-19  浏览次数:20531 次

[着急]多列的值相加,怎么做,具体如下??
字段:x,y,z     都是MONEY类型  

x,y,z字段值可能是null,可能带小数(2.33555000   有多少小数位显示多少),每能是0.0

我显示要把这三字段的“和”值显示在前台,
SQL语句怎么写呢??

我是这么写的
cast((cast(   x   as   int)+cast(y   as   int)+cast(z   as   int))   as   nvarchar)   as   x

得到的值要么为null,要么为整数,
结果不对,小数都没有了??

------解决方案--------------------
IsNull(x, 0.0) + IsNull(y, 0.0) + IsNull(z, 0.0) As x
------解决方案--------------------
select 合计=isnull(x,0)+isnull(y,0)+isnull(z,0) from 表
------解决方案--------------------
Declare @x Money ,@y Money ,@z Money
Select @x = 1.2, @y = 1.3, @z = Null
Select IsNull(@x, 0.0) + IsNull(@y, 0.0) + IsNull(@z, 0.0) As x
--Result
/*
x
2.5000
*/