SQL SERVER多表查询公共字段(判断字段不为空,空字符串,字符串转换小数)

select s.projectname as '项目名称',isnull(sum(CAST(s.moneys as numeric(18,2))),0) as '报销金额' from (


select s.projectname as '项目名称',isnull(sum(CAST(s.moneys as numeric(18,2))),0) as '报销金额' from (

select  b.projectname as projectname, isnull(CAST(b.reimbursement as numeric(18,2)),0) as moneys 
from expensesheet_child b left join expensesheet a on a.id=b.expensesheet_id 
where b.businessprojectcode!='' and b.projectname!='' and b.reimbursement !='' and a.del_flag=0

union all

select  d.projectname as projectname,isnull(CAST(d.SumMoney as numeric(18,2)),0) as moneys 
from travelexpense_child d left join travelexpense c on c.id=d.Travelexpense_id  
where d.businessprojectcode!='' and d.projectname!='' and d.SumMoney !='' and c.del_flag=0
) s
group by s.projectname  order by isnull(sum(CAST(s.moneys as numeric(18,2))),0) desc

猜你喜欢

转载自blog.csdn.net/weixin_42236021/article/details/80838461