if exists (select * from sysobjects where id = OBJECT_ID(N'tOrdCgHead') and OBJECTPROPERTY(id, N'IsView') = 1) drop view tOrdCgHead go create view tOrdCgHead as select BillNo,SupCode,SupName, h.OrgCode as YsOrgCode,(select OrgName from t_shop where OrgCode=h.OrgCode) as YsOrgName, contrno as HtCode,(select contrname from t_contract where contrno = h.contrno) as HtName, (CASE ISNULL(Rzdate,'') WHEN '' THEN NULL ELSE CONVERT(datetime,Rzdate + ' ' + RzTime,120) END) as JzDate, (CASE ISNULL(Rzdate,'') WHEN '' THEN NULL ELSE CONVERT(datetime,DATEADD(DAY,1,CONVERT(datetime,Rzdate,120)) + ' ' + RzTime,120) END) as LastQrTime, s.addr as YsOrgAddress,s.linkMan as YsOrgLinkman,s.tel as YsOrgLkmTel,usercode as CgyCode, username as CgyName,arrivedate as ZdDate, validdate as YxDate, case IsNull(Rzdate,'') when '' then '0' else '9' end as DataStatus,State as YwStatus, '0' AS YsTimes,counts as CgCount,GiveCount,cost as CgHCost, netcost as CgWCost, (cost - netcost) as CgJTaxTotal,h.Remark,(CASE ISNULL(Qrdate,'') WHEN '' THEN NULL ELSE CONVERT(datetime,Qrdate + ' ' + QrTime,120) END) as QrTime, QrCount,QrStatus from t_order_head h left join t_shop s on h.orgcode = s.orgcode where isnull(rzdate,'')<>'' and State <>'5' go if exists (select * from sysobjects where id = OBJECT_ID(N'tOrdCgBody') and OBJECTPROPERTY(id, N'IsView') = 1) drop view tOrdCgBody go create view tOrdCgBody as select BillNo,SerialNo,PluCode,PluName,Barcode,Unit,Spec,CargoNo, PUnit as PackUnit,itemcnt as PackQty,PCount as PackCount,SglCount,Counts as CgCount,GiveCount, jprice as HJPrice,netjprice as WJPrice,JTaxRate,cost as CgHCost,netcost as CgWCost,(cost - netcost) as CgJTaxTotal,Remark, QrCount from t_order_body go