select WLDL,DW,TFTCGSL,TFTCGJE,CZCGSL,CZCGJE,CQCGSL,CQCGJE,YFCGSL,YFCGJE,TFTCGSL2,TFTCGJE2,CZCGSL2,CZCGJE2,CQCGSL2,CQCGJE2,YFCGSL2,YFCGJE2,
SUM(cast(case when TFTCGSL='' then '0' else TFTCGSL end as decimal)
+cast(case when CQCGSL='' then '0' else CQCGSL end as decimal)
+cast(case when CZCGSL='' then '0' else CZCGSL end as decimal)
+cast(case when YFCGSL='' then '0' else YFCGSL end as decimal)) HZCGSL,
SUM(cast(case when TFTCGSL2 is NULL then '0' else TFTCGSL2 end as decimal)
+cast(case when CQCGSL2 is NULL then '0' else CQCGSL2 end as decimal)
+cast(case when CZCGSL2 is NULL then '0' else CZCGSL2 end as decimal)
+cast(case when YFCGSL2 is NULL then '0' else YFCGSL2 end as decimal)) HZCGSL2,
SUM(cast(case when TFTCGJE='' then '0' else TFTCGJE end as decimal)
+cast(case when CQCGJE='' then '0' else CQCGJE end as decimal)
+cast(case when CZCGJE='' then '0' else CZCGJE end as decimal)
+cast(case when YFCGJE='' then '0' else YFCGJE end as decimal)) HZCGJE,
SUM(cast(case when TFTCGJE2 is NULL then '0' else TFTCGJE2 end as decimal)
+cast(case when CQCGJE2 is NULL then '0' else CQCGJE2 end as decimal)
+cast(case when CZCGJE2 is NULL then '0' else CZCGJE2 end as decimal)
+cast(case when YFCGJE2 is NULL then '0' else YFCGJE2 end as decimal)) HZCGJE2
from WWLHZ
group by WLDL,DW,TFTCGSL,TFTCGJE,CZCGSL,CZCGJE,CQCGSL,CQCGJE,YFCGSL,YFCGJE,TFTCGSL2,TFTCGJE2,CZCGSL2,CZCGJE2,CQCGSL2,CQCGJE2,YFCGSL2,YFCGJE2
order by HZCGJE desc
上面的decimal换成decimal(18,2)即可
以下是查询出来结果:(NULL和空的判断不一样)