采购入库单到中间.sql 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. --将采购入库单传递到中间库(委外订单不受约束)
  2. if exists (select * from sysobjects where id = object_id('dbo.usp_transrdrecord01') )
  3. drop procedure dbo.usp_transrdrecord01
  4. go
  5. Create PROCEDURE usp_transrdrecord01
  6. @v_start datetime, --开始时间
  7. @v_end datetime --结束时间
  8. as
  9. select Id into #t_01 from RdRecord01 r
  10. where (dnmaketime>=@v_start and dnmaketime <= @v_end and ISNULL(cDefine5,0) = 0)
  11. or (exists (select Id from RdRecord01 where cBusType='委外加工' and ID=r.ID) )
  12. if @@ROWCOUNT=0 return
  13. delete from wtu..rdrecord01 where exists (select id from #t_01 where ID=wtu..rdrecord01.ID)
  14. delete from wtu..rdrecords01 where exists (select id from #t_01 where ID=wtu..rdrecords01.ID)
  15. ----定义游标(解决排它锁),让游标指向sql查询的结果
  16. --declare cursors cursor for
  17. -- select id from #t_01
  18. --open cursors
  19. -- declare @num int
  20. -- fetch next from cursors into @num
  21. -- while(@@FETCH_STATUS=0)
  22. -- begin
  23. -- delete from wtu..RdRecord01 where ID=@num
  24. -- delete from wtu..rdrecords01 where ID=@num
  25. -- fetch next from cursors into @num
  26. -- end
  27. --close cursors
  28. --deallocate cursors --释放游标,释放完不能open
  29. insert into wtu..RdRecord01
  30. (ID,
  31. bRdFlag,
  32. cVouchType,
  33. cBusType,
  34. cSource,
  35. cBusCode,
  36. cWhCode,
  37. dDate,
  38. cCode,
  39. cRdCode,
  40. cDepCode,
  41. cPersonCode,
  42. cPTCode,
  43. cSTCode,
  44. cCusCode,
  45. cVenCode,
  46. cOrderCode,
  47. cARVCode,
  48. cBillCode,
  49. cDLCode,
  50. cProBatch,
  51. cHandler,
  52. cMemo,
  53. bTransFlag,
  54. cAccounter,
  55. cMaker,
  56. cDefine1,
  57. cDefine2,
  58. cDefine3,
  59. cDefine4,
  60. cDefine5,
  61. cDefine6,
  62. cDefine7,
  63. cDefine8,
  64. cDefine9,
  65. cDefine10,
  66. dKeepDate,
  67. dVeriDate,
  68. bpufirst,
  69. biafirst,
  70. iMQuantity,
  71. dARVDate,
  72. cChkCode,
  73. dChkDate,
  74. cChkPerson,
  75. VT_ID,
  76. bIsSTQc,
  77. cDefine11,
  78. cDefine12,
  79. cDefine13,
  80. cDefine14,
  81. cDefine15,
  82. cDefine16,
  83. gspcheck,
  84. ipurorderid,
  85. ipurarriveid,
  86. iarriveid,
  87. isalebillid,
  88. iTaxRate,
  89. iExchRate,
  90. cExch_Name,
  91. bOMFirst,
  92. bFromPreYear,
  93. bIsLsQuery,
  94. bIsComplement,
  95. iDiscountTaxType,
  96. ireturncount,
  97. iverifystate,
  98. iswfcontrolled,
  99. cModifyPerson,
  100. dModifyDate,
  101. dnmaketime,
  102. dnmodifytime,
  103. dnverifytime,
  104. bredvouch,
  105. cVenPUOMProtocol,
  106. dCreditStart,
  107. iCreditPeriod,
  108. dGatheringDate,
  109. bCredit,
  110. iFlowId,
  111. cPZID,
  112. cSourceLs,
  113. cSourceCodeLs,
  114. iPrintCount,
  115. csysbarcode,
  116. cCurrentAuditor,
  117. cCheckSignFlag,
  118. cGCRouteCode
  119. )
  120. select
  121. r.ID,
  122. bRdFlag,
  123. cVouchType,
  124. cBusType,
  125. cSource,
  126. cBusCode,
  127. cWhCode,
  128. dDate,
  129. cCode,
  130. cRdCode,
  131. cDepCode,
  132. cPersonCode,
  133. cPTCode,
  134. cSTCode,
  135. cCusCode,
  136. cVenCode,
  137. cOrderCode,
  138. cARVCode,
  139. cBillCode,
  140. cDLCode,
  141. cProBatch,
  142. cHandler,
  143. cMemo,
  144. bTransFlag,
  145. cAccounter,
  146. cMaker,
  147. cDefine1,
  148. cDefine2,
  149. cDefine3,
  150. cDefine4,
  151. cDefine5,
  152. cDefine6,
  153. cDefine7,
  154. cDefine8,
  155. cDefine9,
  156. cDefine10,
  157. dKeepDate,
  158. dVeriDate,
  159. bpufirst,
  160. biafirst,
  161. iMQuantity,
  162. dARVDate,
  163. cChkCode,
  164. dChkDate,
  165. cChkPerson,
  166. VT_ID,
  167. bIsSTQc,
  168. cDefine11,
  169. cDefine12,
  170. cDefine13,
  171. cDefine14,
  172. cDefine15,
  173. cDefine16,
  174. gspcheck,
  175. ipurorderid,
  176. ipurarriveid,
  177. iarriveid,
  178. isalebillid,
  179. iTaxRate,
  180. iExchRate,
  181. cExch_Name,
  182. bOMFirst,
  183. bFromPreYear,
  184. bIsLsQuery,
  185. bIsComplement,
  186. iDiscountTaxType,
  187. ireturncount,
  188. iverifystate,
  189. iswfcontrolled,
  190. cModifyPerson,
  191. dModifyDate,
  192. dnmaketime,
  193. dnmodifytime,
  194. dnverifytime,
  195. bredvouch,
  196. cVenPUOMProtocol,
  197. dCreditStart,
  198. iCreditPeriod,
  199. dGatheringDate,
  200. bCredit,
  201. iFlowId,
  202. cPZID,
  203. cSourceLs,
  204. cSourceCodeLs,
  205. iPrintCount,
  206. csysbarcode,
  207. cCurrentAuditor,
  208. cCheckSignFlag,
  209. cGCRouteCode
  210. from RdRecord01 r where exists(select ID from #t_01 t where t.ID=r.ID)
  211. ---------------------------------------------
  212. insert into wtu..RdRecords01
  213. (AutoID,
  214. ID,
  215. cInvCode,
  216. iNum,
  217. iQuantity,
  218. iUnitCost,
  219. iPrice,
  220. iAPrice,
  221. iPUnitCost,
  222. iPPrice,
  223. cBatch,
  224. cVouchCode,
  225. cInVouchCode,
  226. cinvouchtype,
  227. iSOutQuantity,
  228. iSOutNum,
  229. cFree1,
  230. cFree2,
  231. iFlag,
  232. dSDate,
  233. iTax,
  234. iSQuantity,
  235. iSNum,
  236. iMoney,
  237. iFNum,
  238. iFQuantity,
  239. dVDate,
  240. cPosition,
  241. cDefine22,
  242. cDefine23,
  243. cDefine24,
  244. cDefine25,
  245. cDefine26,
  246. cDefine27,
  247. cItem_class,
  248. cItemCode,
  249. iPOsID,
  250. fACost,
  251. cName,
  252. cItemCName,
  253. cFree3,
  254. cFree4,
  255. cFree5,
  256. cFree6,
  257. cFree7,
  258. cFree8,
  259. cFree9,
  260. cFree10,
  261. cBarCode,
  262. iNQuantity,
  263. iNNum,
  264. cAssUnit,
  265. dMadeDate,
  266. iMassDate,
  267. cDefine28,
  268. cDefine29,
  269. cDefine30,
  270. cDefine31,
  271. cDefine32,
  272. cDefine33,
  273. cDefine34,
  274. cDefine35,
  275. cDefine36,
  276. cDefine37,
  277. iCheckIds,
  278. cBVencode,
  279. chVencode,
  280. bGsp,
  281. cGspState,
  282. iArrsId,
  283. cCheckCode,
  284. iCheckIdBaks,
  285. cRejectCode,
  286. iRejectIds,
  287. cCheckPersonCode,
  288. dCheckDate,
  289. iOriTaxCost,
  290. iOriCost,
  291. iOriMoney,
  292. iOriTaxPrice,
  293. ioriSum,
  294. iTaxRate,
  295. iTaxPrice,
  296. iSum,
  297. bTaxCost,
  298. cPOID,
  299. cMassUnit,
  300. iMaterialFee,
  301. iProcessCost,
  302. iProcessFee,
  303. dMSDate,
  304. iSMaterialFee,
  305. iSProcessFee,
  306. iOMoDID,
  307. strContractId,
  308. strCode,
  309. bChecked,
  310. bRelated,
  311. iOMoMID,
  312. iMatSettleState,
  313. iBillSettleCount,
  314. bLPUseFree,
  315. iOriTrackID,
  316. coritracktype,
  317. cbaccounter,
  318. dbKeepDate,
  319. bCosting,
  320. iSumBillQuantity,
  321. bVMIUsed,
  322. iVMISettleQuantity,
  323. iVMISettleNum,
  324. cvmivencode,
  325. iInvSNCount,
  326. cwhpersoncode,
  327. cwhpersonname,
  328. impcost,
  329. iIMOSID,
  330. iIMBSID,
  331. cbarvcode,
  332. dbarvdate,
  333. iinvexchrate,
  334. comcode,
  335. strContractGUID,
  336. iExpiratDateCalcu
  337. )
  338. select
  339. AutoID,
  340. r.ID,
  341. cInvCode,
  342. iNum,
  343. iQuantity,
  344. iUnitCost,
  345. iPrice,
  346. iAPrice,
  347. iPUnitCost,
  348. iPPrice,
  349. cBatch,
  350. cVouchCode,
  351. cInVouchCode,
  352. cinvouchtype,
  353. iSOutQuantity,
  354. iSOutNum,
  355. cFree1,
  356. cFree2,
  357. iFlag,
  358. dSDate,
  359. iTax,
  360. iSQuantity,
  361. iSNum,
  362. iMoney,
  363. iFNum,
  364. iFQuantity,
  365. dVDate,
  366. cPosition,
  367. cDefine22,
  368. cDefine23,
  369. cDefine24,
  370. cDefine25,
  371. cDefine26,
  372. cDefine27,
  373. cItem_class,
  374. cItemCode,
  375. iPOsID,
  376. fACost,
  377. cName,
  378. cItemCName,
  379. cFree3,
  380. cFree4,
  381. cFree5,
  382. cFree6,
  383. cFree7,
  384. cFree8,
  385. cFree9,
  386. cFree10,
  387. cBarCode,
  388. iNQuantity,
  389. iNNum,
  390. cAssUnit,
  391. dMadeDate,
  392. iMassDate,
  393. cDefine28,
  394. cDefine29,
  395. cDefine30,
  396. cDefine31,
  397. cDefine32,
  398. cDefine33,
  399. cDefine34,
  400. cDefine35,
  401. cDefine36,
  402. cDefine37,
  403. iCheckIds,
  404. cBVencode,
  405. chVencode,
  406. bGsp,
  407. cGspState,
  408. iArrsId,
  409. cCheckCode,
  410. iCheckIdBaks,
  411. cRejectCode,
  412. iRejectIds,
  413. cCheckPersonCode,
  414. dCheckDate,
  415. iOriTaxCost,
  416. iOriCost,
  417. iOriMoney,
  418. iOriTaxPrice,
  419. ioriSum,
  420. iTaxRate,
  421. iTaxPrice,
  422. iSum,
  423. bTaxCost,
  424. cPOID,
  425. cMassUnit,
  426. iMaterialFee,
  427. iProcessCost,
  428. iProcessFee,
  429. dMSDate,
  430. iSMaterialFee,
  431. iSProcessFee,
  432. iOMoDID,
  433. strContractId,
  434. strCode,
  435. bChecked,
  436. bRelated,
  437. iOMoMID,
  438. iMatSettleState,
  439. iBillSettleCount,
  440. bLPUseFree,
  441. iOriTrackID,
  442. coritracktype,
  443. cbaccounter,
  444. dbKeepDate,
  445. bCosting,
  446. iSumBillQuantity,
  447. bVMIUsed,
  448. iVMISettleQuantity,
  449. iVMISettleNum,
  450. cvmivencode,
  451. iInvSNCount,
  452. cwhpersoncode,
  453. cwhpersonname,
  454. impcost,
  455. iIMOSID,
  456. iIMBSID,
  457. cbarvcode,
  458. dbarvdate,
  459. iinvexchrate,
  460. comcode,
  461. strContractGUID,
  462. iExpiratDateCalcu
  463. from RdRecords01 r where exists(select ID from #t_01 t where t.ID=r.ID)
  464. --释放临时表
  465. drop table #t_01