---------/*查出含有明细而没有凭证单指令:*/------------
select * from FAM_CredenceBillDetail where ParentBillCode not in
(select code from FAM_CredenceBill) order by ParentBillCode
---------/*根据凭证明细来插入一张全新的凭证单*/------------
INSERT INTO [EMSXDB].[dbo].[FAM_CredenceBill]
([Id]
,[Code]
,[BusiDate]
,[ChargeUserCode]
,[Acc4ChargeUserName]
,[CheckUserCode]
,[Acc4CheckUserName]
,[Remark]
,[PrintCounter]
,[CanUpdate]
,[CanDelete]
,[IsChecked]
,[Sys4CreateTime]
,[Sys4CheckTime]
,[Sys4CreateUserCode]
,[Acc4Sys4CreateUserName]
,[Sys4LastUpdateUserCode]
,[Acc4Sys4LastUpdateUserName]
,[Sys4Version]
,[IsMatchedByPaperBill]
,[ShopCode]
,[Sys4ProduceBancCiCode]
,[Sys4ProduceBancCiName]
,[Sys4ProduceGroupId]
,[Sys4ProduceGroupName]
,[AccPID]
,[BusinessBillCode]
,[EPAFileRootPath]
,[Sys4CorporateStatus])
select newid()
,'PZ18081411658' ---------/*根据凭证明细获取的凭证单号*/-----
,BusiDate
,ChargeUserCode
,Acc4ChargeUserName
,CheckUserCode
,Acc4CheckUserName
,Remark
,PrintCounter
,CanUpdate
,CanDelete
,IsChecked
,Sys4CreateTime
,Sys4CheckTime
,Sys4CreateUserCode
,Acc4Sys4CreateUserName
,Sys4LastUpdateUserCode
,Acc4Sys4LastUpdateUserName
,Sys4Version
,IsMatchedByPaperBill
,ShopCode
,Sys4ProduceBancCiCode
,Sys4ProduceBancCiName
,Sys4ProduceGroupId
,Sys4ProduceGroupName
,201410 ---------/*根据凭证明细所在会计期间,获取的会计期间时间*/-----
,Code
,EPAFileRootPath
,Sys4CorporateStatus
from RSM_GatheringBill where code='GJ18081411516' ---------/*根据凭证明细获取的结算单号*/-----