语句如下:
if exists (select * from tempdb..sysobjects where name = N'[TMPUF_464398971_Lstdemo732demo874]' and type=N'U')
Drop Table TempDB..[TMPUF_464398971_Lstdemo732demo874]
Select IDENTITY(int,1,1) as IDOrder, ' ' as selcol,dverifydate,ufts,(om_mohead.moid) as moid,cbustype,ccode,ddate,cptcode,cptname,cvencode,
cvenabbname,cdepcode,cdepname,cpersoncode,cpersonname,cpaycode,cpayname,ibargain,cscname,carrivalplace,icost,cmemo,ipertaxrate,cexch_name,nflat,cmaker,
cverifier,cchanger,ccloser,clocker,modetailsid,cinvcode,cinvaddcode,cinvname,cveninvcode,cveninvname,cinvstd,cinvm_unit,cinva_unit,citemcode,citemname,
citem_class,citem_name,bgsp,inum,iquantity,iquotedprice,iunitprice,itaxprice,imoney,itax,isum,idiscount,inatunitprice,inatmoney,inattax,inatsum,
inatdiscount,darrivedate,dstartdate,cbcloser,sotype,csocode,sodid,irowno,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,
cinvdefine1,cinvdefine2,cinvdefine3,cinvdefine4,cinvdefine5,cinvdefine6,cinvdefine7,cinvdefine8,cinvdefine9,cinvdefine10,cinvdefine11,cinvdefine12,
cinvdefine13,cinvdefine14,cinvdefine15,cinvdefine16,cdefine1,cdefine2,cdefine3,cdefine4,cdefine5,cdefine6,cdefine7,cdefine8,cdefine9,cdefine10,
cdefine11,cdefine12,cdefine13,cdefine14,cdefine15,cdefine16,cdefine22,cdefine23,cdefine24,cdefine25,cdefine26,cdefine27,cdefine28,cdefine29,
cdefine30,cdefine31,cdefine32,cdefine33,cdefine34,cdefine35,cdefine36,cdefine37,cvendefine1,cvendefine2,cvendefine3,cvendefine4,cvendefine5,
cvendefine6,cvendefine7,cvendefine8,cvendefine9,cvendefine10,cvendefine11,cvendefine12,cvendefine13,cvendefine14,cvendefine15,cvendefine16,cmodifier,
dcreatetime,dmodifydate,dmodifytime,iarrqty,dverifytime,ireceivedqty,itaxrate,daltertime,cdemandmemo,csource,cupsocode,dbclosedate,dbclosetime,
cchangeverifier,dchangeverifydate,dchangeverifytime,ivouchrowno,cunitid,cvenpuomprotocol,cvenpuomprotocolname,dclosedate,dclosetime,iprintcount,
(case when isnull(iswfcontrolled,0)=0 and isnull(iverifystatenew,0)=0 then 100 else isnull(iverifystatenew,0) end) as iverifystatus,ccontactcode,
cvenperson,cvenphone,cmobilephone,cvenbank,cvenaccount,csrccode,cbmemo,csysbarcode,cbsysbarcode,(cvoucherstate) as cvoucherstate,
(case when (isnull(iarrqty,0) >= isnull(iquantity,0) or isnull(ireceivedqty,0) >= isnull(iquantity,0)) and isnull(iquantity,0) > 0
then N'到货完成' else N'到货未完成' end) as carrivestate,(case when isnull(ireceivedqty,0) >= isnull(iquantity,0) and isnull(iquantity,0) > 0
then N'入库完成' else N'入库未完成' end) as creceivestate,(case when isnull(iinvqty,0) >= isnull(iquantity,0) and isnull(iquantity,0) > 0
then N'开票完成' else N'开票未完成' end) as cbillstate,(case when isnull(ioritotal,0) >= isnull(isum,0) and isnull(isum,0) > 0
then N'付款完成' else N'付款未完成' end) as cpaystate,ccurrentauditor into TempDB..[TMPUF_464398971_Lstdemo732demo874]
From om_mohead with(nolock) inner join om_mobody with(nolock) on om_mohead.moid=om_mobody.moid
Where 1=1 And ( 1=1 And ((dDate >= N'2018-08-01') And (dDate <= N'2018-08-13')))
and (om_mobody.iQuantity-ISNULL(om_mobody.iReceivedQTY,0))<=0 AND (ISNULL(om_mobody.cbcloser,'')='')