select cus.cus_name as 工地,
convert(char(10),da.add_date,23) as 日期,
case when da.direction='支出' then da.amount else '' end as 进账,
da.digest as 项目,
case when isnull(vd.vd_name,'')<>'' then vd.vd_name else ele.ele_name end as 收款人,
case when cst.cst_name='现金购买' then da.amount else 0 end as 金额,
case when cst.cst_name='水电工' then da.amount else 0 end as 水电工,
case when cst.cst_name='泥工' then da.amount else 0 end as 泥工,
case when cst.cst_name='木工' then da.amount else 0 end as 木工,
case when cst.cst_name='油漆工' then da.amount else 0 end as 油漆工,
case when cst.cst_name='杂工' then da.amount else 0 end as 杂工,
da.amount as 合计
from Ling_DayAccount da
left join Base_Customer cus on cus.cus_id=da.cus_id
left join Base_Vendor vd on vd.vd_id=da.vd_id
left join Base_Employee ele on ele.ele_id=da.ele_id
left join Base_Cost cst on cst.cst_id=da.cst_id
where isnull(da.cus_id,'')<>''
order by da.add_date,da.da_id
--select * from Base_Cost

