if exists (select * from sysobjects where id = OBJECT_ID(N'tAcpJsRcpBody') and OBJECTPROPERTY(id, N'IsView') = 1) drop view tAcpJsRcpBody go create view tAcpJsRcpBody as select b.BillNo,b.orgcode as YwOrgCode,(select orgname from t_shop where orgcode = b.orgcode) as YwOrgName, YwBillNo,billtype as YwType, case billtype when '0' then '验收单' when '1' then '退货单' when '2' then '进价调整单' when '3' then '直送单' when '4' then '直送退货' when '5' then '直送进价调整单' when '6' then '配送单' when '7' then '配送退货单' when '8' then '配送进价调整单' end as YwTypeName, (CASE ISNULL(Rzdate,'') WHEN '' THEN NULL ELSE CONVERT(datetime,Rzdate + ' ' + RzTime,120) END) as JzDate, case when billtype = '0' or billtype = '3' then (select cost from t_accept_head where billno = b.YwBillNo) when billtype = '1' or billtype = '4' then (select cost from t_return_head where billno = b.YwBillNo) when billtype = '2' or billtype = '5' or billtype = '8' then (select cjcost from t_adjbuyprice_head where billno = b.YwBillNo) when billtype = '6' or billtype = '7' then (select zpamount from t_dist_head where billno = b.YwBillNo) end as HJTotal, case when billtype = '0' or billtype = '3' then (select netcost from t_accept_head where billno = b.YwBillNo) when billtype = '1' or billtype = '4' then (select netcost from t_return_head where billno = b.YwBillNo) when billtype = '2' or billtype = '5' or billtype = '8' then (select netcjcost from t_adjbuyprice_head where billno = b.YwBillNo) when billtype = '6' or billtype = '7' then (select zpnetamount from t_dist_head where billno = b.YwBillNo) end as WJTotal, case when billtype = '0' or billtype = '3' then (select cost-netcost from t_accept_head where billno = b.YwBillNo) when billtype = '1' or billtype = '4' then (select cost-netcost from t_return_head where billno = b.YwBillNo) when billtype = '2' or billtype = '5' or billtype = '8' then (select netcost-netcjcost from t_adjbuyprice_head where billno = b.YwBillNo) when billtype = '6' or billtype = '7' then (select zpamount-zpnetamount from t_dist_head where billno = b.YwBillNo) end as JTaxTotal from t_paysoa_body b, t_paysoa_head h where h.billno = b.billno go