其他出库单到中间.sql 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. --将其他出库单传递到中间库
  2. if exists (select * from sysobjects where id = object_id('dbo.usp_transrdrecord09') )
  3. drop procedure dbo.usp_transrdrecord09
  4. go
  5. Create PROCEDURE usp_transrdrecord09
  6. @v_start datetime, --开始时间
  7. @v_end datetime --结束时间
  8. as
  9. --cDefine5=1 代表是从旺店通传递回来的数据,不需要回传
  10. --其他出库音id
  11. select Id into #t_1 from RdRecord09 where dnmaketime>=@v_start and dnmaketime <= @v_end and ISNULL(cDefine5,0) = 0 and (cDefine1 <> '来源旺店通' or cDefine1 is null)
  12. --材料出库单id
  13. select Id into #t_01 from rdrecord11 r
  14. where (dnmaketime>=@v_start and dnmaketime <= @v_end and ISNULL(cDefine5,0) = 0)
  15. --if @@ROWCOUNT = 0 return
  16. --删除其他出库中间库已存在的资料
  17. delete from wtu..rdrecord09 where exists (select id from #t_1 where ID=wtu..rdrecord09.ID)
  18. delete from wtu..rdrecords09 where exists (select id from #t_1 where ID=wtu..rdrecords09.ID)
  19. --删除材料出库中间库已经存在的资料
  20. delete from wtu..rdrecord09 where exists (select id from #t_01 where ID=wtu..rdrecord09.ID ) and ( cBusType<>'其他出库' or cBusType<>'组装出库')
  21. delete from wtu..rdrecords09 where exists (select id from #t_01 where ID=wtu..rdrecords09.ID ) and text_flag=1
  22. --其他出库主表数据
  23. insert into wtu..RdRecord09(
  24. ID,
  25. bRdFlag,
  26. cVouchType,
  27. cBusType,
  28. cSource,
  29. cBusCode,
  30. cWhCode,
  31. dDate,
  32. cCode,
  33. cRdCode,
  34. cDepCode,
  35. cPersonCode,
  36. cPTCode,
  37. cSTCode,
  38. cCusCode,
  39. cVenCode,
  40. cOrderCode,
  41. cARVCode,
  42. cBillCode,
  43. cDLCode,
  44. cProBatch,
  45. cHandler,
  46. cMemo,
  47. bTransFlag,
  48. cAccounter,
  49. cMaker,
  50. cDefine1,
  51. cDefine2,
  52. cDefine3,
  53. cDefine4,
  54. cDefine5,
  55. cDefine6,
  56. cDefine7,
  57. cDefine8,
  58. cDefine9,
  59. cDefine10,
  60. dKeepDate,
  61. dVeriDate,
  62. bpufirst,
  63. biafirst,
  64. iMQuantity,
  65. dARVDate,
  66. cChkCode,
  67. dChkDate,
  68. cChkPerson,
  69. VT_ID,
  70. bIsSTQc,
  71. cDefine11,
  72. cDefine12,
  73. cDefine13,
  74. cDefine14,
  75. cDefine15,
  76. cDefine16,
  77. gspcheck,
  78. iExchRate,
  79. cExch_Name,
  80. cShipAddress,
  81. caddcode,
  82. bOMFirst,
  83. bFromPreYear,
  84. bIsLsQuery,
  85. bIsComplement,
  86. iDiscountTaxType,
  87. iBG_OverFlag,
  88. cBG_Auditor,
  89. cBG_AuditTime,
  90. ControlResult,
  91. ireturncount,
  92. iverifystate,
  93. iswfcontrolled,
  94. cModifyPerson,
  95. dModifyDate,
  96. dnmaketime,
  97. dnmodifytime,
  98. dnverifytime,
  99. bredvouch,
  100. iFlowId,
  101. cPZID,
  102. cSourceLs,
  103. cSourceCodeLs,
  104. iPrintCount,
  105. ctransflag,
  106. csysbarcode,
  107. cCurrentAuditor,
  108. cCheckSignFlag
  109. )
  110. select r.ID,bRdFlag,
  111. cVouchType,
  112. cBusType,
  113. cSource,
  114. cBusCode,
  115. cWhCode,
  116. dDate,
  117. cCode,
  118. cRdCode,
  119. cDepCode,
  120. cPersonCode,
  121. cPTCode,
  122. cSTCode,
  123. cCusCode,
  124. cVenCode,
  125. cOrderCode,
  126. cARVCode,
  127. cBillCode,
  128. cDLCode,
  129. cProBatch,
  130. cHandler,
  131. cMemo,
  132. bTransFlag,
  133. cAccounter,
  134. cMaker,
  135. cDefine1,
  136. cDefine2,
  137. cDefine3,
  138. cDefine4,
  139. cDefine5,
  140. cDefine6,
  141. cDefine7,
  142. cDefine8,
  143. cDefine9,
  144. cDefine10,
  145. dKeepDate,
  146. dVeriDate,
  147. bpufirst,
  148. biafirst,
  149. iMQuantity,
  150. dARVDate,
  151. cChkCode,
  152. dChkDate,
  153. cChkPerson,
  154. VT_ID,
  155. bIsSTQc,
  156. cDefine11,
  157. cDefine12,
  158. cDefine13,
  159. cDefine14,
  160. cDefine15,
  161. cDefine16,
  162. gspcheck,
  163. iExchRate,
  164. cExch_Name,
  165. cShipAddress,
  166. caddcode,
  167. bOMFirst,
  168. bFromPreYear,
  169. bIsLsQuery,
  170. bIsComplement,
  171. iDiscountTaxType,
  172. iBG_OverFlag,
  173. cBG_Auditor,
  174. cBG_AuditTime,
  175. ControlResult,
  176. ireturncount,
  177. iverifystate,
  178. iswfcontrolled,
  179. cModifyPerson,
  180. dModifyDate,
  181. dnmaketime,
  182. dnmodifytime,
  183. dnverifytime,
  184. bredvouch,
  185. iFlowId,
  186. cPZID,
  187. cSourceLs,
  188. cSourceCodeLs,
  189. iPrintCount,
  190. ctransflag,
  191. csysbarcode,
  192. cCurrentAuditor,
  193. cCheckSignFlag
  194. from RdRecord09 r where exists(select ID from #t_1 t where t.ID=r.ID)
  195. --其他出库子表数据
  196. insert into wtu..rdrecords09 (
  197. AutoID,
  198. ID,
  199. cInvCode,
  200. iNum,
  201. iQuantity,
  202. iUnitCost,
  203. iPrice,
  204. iAPrice,
  205. iPUnitCost,
  206. iPPrice,
  207. cBatch,
  208. cVouchCode,
  209. cInVouchCode,
  210. cinvouchtype,
  211. iSOutQuantity,
  212. iSOutNum,
  213. coutvouchid,
  214. coutvouchtype,
  215. iSRedOutQuantity,
  216. iSRedOutNum,
  217. cFree1,
  218. cFree2,
  219. iFlag,
  220. iFNum,
  221. iFQuantity,
  222. dVDate,
  223. iTrIds,
  224. cPosition,
  225. cDefine22,
  226. cDefine23,
  227. cDefine24,
  228. cDefine25,
  229. cDefine26,
  230. cDefine27,
  231. cItem_class,
  232. cItemCode,
  233. iDLsID,
  234. cName,
  235. cItemCName,
  236. cFree3,
  237. cFree4,
  238. cFree5,
  239. cFree6,
  240. cFree7,
  241. cFree8,
  242. cFree9,
  243. cFree10,
  244. cBarCode,
  245. iNQuantity,
  246. iNNum,
  247. cAssUnit,
  248. dMadeDate,
  249. iMassDate,
  250. cDefine28,
  251. cDefine29,
  252. cDefine30,
  253. cDefine31,
  254. cDefine32,
  255. cDefine33,
  256. cDefine34,
  257. cDefine35,
  258. cDefine36,
  259. cDefine37,
  260. iCheckIds,
  261. cBVencode,
  262. bGsp,
  263. cGspState,
  264. cCheckCode,
  265. iCheckIdBaks,
  266. cRejectCode,
  267. iRejectIds,
  268. cCheckPersonCode,
  269. dCheckDate,
  270. cMassUnit,
  271. bChecked,
  272. iEqDID,
  273. bLPUseFree,
  274. iRSRowNO,
  275. iOriTrackID,
  276. coritracktype,
  277. cbaccounter,
  278. dbKeepDate,
  279. bCosting,
  280. bVMIUsed,
  281. iVMISettleQuantity,
  282. iVMISettleNum,
  283. cvmivencode,
  284. iInvSNCount,
  285. cwhpersoncode,
  286. cwhpersonname,
  287. cserviceoid,
  288. cbserviceoid,
  289. iinvexchrate,
  290. cbdlcode
  291. )
  292. select
  293. AutoID,
  294. r.ID,
  295. cInvCode,
  296. iNum,
  297. iQuantity,
  298. iUnitCost,
  299. iPrice,
  300. iAPrice,
  301. iPUnitCost,
  302. iPPrice,
  303. cBatch,
  304. cVouchCode,
  305. cInVouchCode,
  306. cinvouchtype,
  307. iSOutQuantity,
  308. iSOutNum,
  309. coutvouchid,
  310. coutvouchtype,
  311. iSRedOutQuantity,
  312. iSRedOutNum,
  313. cFree1,
  314. cFree2,
  315. iFlag,
  316. iFNum,
  317. iFQuantity,
  318. dVDate,
  319. iTrIds,
  320. cPosition,
  321. cDefine22,
  322. cDefine23,
  323. cDefine24,
  324. cDefine25,
  325. cDefine26,
  326. cDefine27,
  327. cItem_class,
  328. cItemCode,
  329. iDLsID,
  330. cName,
  331. cItemCName,
  332. cFree3,
  333. cFree4,
  334. cFree5,
  335. cFree6,
  336. cFree7,
  337. cFree8,
  338. cFree9,
  339. cFree10,
  340. cBarCode,
  341. iNQuantity,
  342. iNNum,
  343. cAssUnit,
  344. dMadeDate,
  345. iMassDate,
  346. cDefine28,
  347. cDefine29,
  348. cDefine30,
  349. cDefine31,
  350. cDefine32,
  351. cDefine33,
  352. cDefine34,
  353. cDefine35,
  354. cDefine36,
  355. cDefine37,
  356. iCheckIds,
  357. cBVencode,
  358. bGsp,
  359. cGspState,
  360. cCheckCode,
  361. iCheckIdBaks,
  362. cRejectCode,
  363. iRejectIds,
  364. cCheckPersonCode,
  365. dCheckDate,
  366. cMassUnit,
  367. bChecked,
  368. iEqDID,
  369. bLPUseFree,
  370. iRSRowNO,
  371. iOriTrackID,
  372. coritracktype,
  373. cbaccounter,
  374. dbKeepDate,
  375. bCosting,
  376. bVMIUsed,
  377. iVMISettleQuantity,
  378. iVMISettleNum,
  379. cvmivencode,
  380. iInvSNCount,
  381. cwhpersoncode,
  382. cwhpersonname,
  383. cserviceoid,
  384. cbserviceoid,
  385. iinvexchrate,
  386. cbdlcode
  387. from rdrecords09 r where exists(select ID from #t_1 t where t.ID=r.ID)
  388. --材料出库主表数据
  389. --set identity_insert wtu..rdrecord09 ON--打开
  390. insert into wtu..rdrecord09(ID,BRDFLAG,CVOUCHTYPE,CBUSTYPE,CSOURCE,CBUSCODE,CWHCODE,DDATE,CCODE,CRDCODE,CDEPCODE,CPERSONCODE,CPTCODE,CSTCODE,CCUSCODE,CVENCODE,CORDERCODE,CARVCODE,CBILLCODE,CDLCODE,CPROBATCH,CHANDLER,CMEMO,BTRANSFLAG,CACCOUNTER,CMAKER,CDEFINE1,CDEFINE2,CDEFINE3,CDEFINE4,CDEFINE5,CDEFINE6,CDEFINE7,CDEFINE8,CDEFINE9,CDEFINE10,DKEEPDATE,DVERIDATE,BPUFIRST,BIAFIRST,bIsSTQc)
  391. select r.ID,BRDFLAG,CVOUCHTYPE,CBUSTYPE,CSOURCE,CBUSCODE,CWHCODE,DDATE,CCODE,CRDCODE,CDEPCODE,CPERSONCODE,CPTCODE,CSTCODE,CCUSCODE,CVENCODE,CORDERCODE,CARVCODE,CBILLCODE,CDLCODE,CPROBATCH,CHANDLER,CMEMO,BTRANSFLAG,CACCOUNTER,CMAKER,CDEFINE1,CDEFINE2,CDEFINE3,CDEFINE4,CDEFINE5,CDEFINE6,CDEFINE7,CDEFINE8,CDEFINE9,CDEFINE10,DKEEPDATE,DVERIDATE,BPUFIRST,BIAFIRST,0 from rdrecord11 r where exists(select ID from #t_01 t where t.ID=r.ID)
  392. --set identity_insert wtu..rdrecord09 OFF--关闭
  393. --材料出库子表数据
  394. --set identity_insert wtu..rdrecords09 ON--打开
  395. insert into wtu..rdrecords09(AUTOID,ID,CINVCODE,INUM,IQUANTITY,IUNITCOST,IPRICE,IAPRICE,IPUNITCOST,IPPRICE,CBATCH,CVOUCHCODE,CINVOUCHCODE,CINVOUCHTYPE,ISOUTQUANTITY,ISOUTNUM,COUTVOUCHID,COUTVOUCHTYPE,ISREDOUTQUANTITY,ISREDOUTNUM,CFREE1,CFREE2,IFLAG,IFNUM,IFQUANTITY,DVDATE,ITRIDS,CPOSITION,CDEFINE22,CDEFINE23,CDEFINE24,CDEFINE25,CDEFINE26,CDEFINE27,CITEM_CLASS,CITEMCODE,CNAME,CITEMCNAME,CFREE3,CFREE4,CFREE5,CFREE6,CFREE7,CFREE8,CFREE9,CFREE10,CBARCODE,INQUANTITY,INNUM,CASSUNIT,text_flag)
  396. select AUTOID,r.ID,CINVCODE,INUM,IQUANTITY,IUNITCOST,IPRICE,IAPRICE,IPUNITCOST,IPPRICE,CBATCH,CVOUCHCODE,CINVOUCHCODE,CINVOUCHTYPE,ISOUTQUANTITY,ISOUTNUM,COUTVOUCHID,COUTVOUCHTYPE,ISREDOUTQUANTITY,ISREDOUTNUM,CFREE1,CFREE2,IFLAG,IFNUM,IFQUANTITY,DVDATE,ITRIDS,CPOSITION,CDEFINE22,CDEFINE23,CDEFINE24,CDEFINE25,CDEFINE26,CDEFINE27,CITEM_CLASS,CITEMCODE,CNAME,CITEMCNAME,CFREE3,CFREE4,CFREE5,CFREE6,CFREE7,CFREE8,CFREE9,CFREE10,CBARCODE,INQUANTITY,INNUM,CASSUNIT,1 from rdrecords11 as r where exists(select ID from #t_01 t where t.ID=r.ID)
  397. --set identity_insert wtu..rdrecords09 OFF--关闭
  398. --释放临时表
  399. drop table #t_1
  400. drop table #t_01
  401. --