Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.57 KB | None | 0 0
  1.  
  2. SET ANSI_NULLS ON
  3. GO
  4. SET QUOTED_IDENTIFIER ON
  5. GO
  6.  
  7. ALTER PROC [dbo].[StockMove_rp1069_ID]
  8. -- StockMove_rp1069_InsertData
  9.     @syear varchar(10),
  10.     @fp1 varchar(20),       -- from item
  11.     @fp2 varchar(20),       -- to item
  12.     @fp3 varchar(20),       -- from category
  13.     @fp4 varchar(20),       -- to category
  14.     @fp5 varchar(20),       -- from sub category
  15.     @fp6 varchar(20),       -- to sub category
  16.     @fp7 varchar(20),       -- from item group
  17.     @fp8 varchar(20),       -- to item group
  18.     @fp9 varchar(20),       -- from sub item group
  19.     @fp10 varchar(20)       -- to sub item group
  20.  
  21. as
  22. declare @sdate nvarchar(11)
  23. declare @edate nvarchar(11)
  24.  
  25. declare @itemno varchar(30)
  26. declare @desp varchar(100)
  27. declare @category varchar(50)
  28. declare @group varchar(50)
  29. declare @subcategory varchar(50)
  30. declare @subgroup varchar(50)
  31. declare @qty int
  32. declare @month varchar(10)
  33. declare @year varchar(10)
  34.  
  35. set @sdate = '01/jan/' + @syear
  36. set @edate = '31/dec/' + @syear
  37.  
  38. SET NOCOUNT ON
  39.  
  40. if object_id('GTEC1069') is not null
  41. truncate table GTEC1069;
  42.  
  43. -->> part1: get do record
  44. declare do_cursor cursor for
  45. select b.itemno, c.desp1, isnull(c.category,'')category, isnull(c.igroup,'')igroup, isnull(c.subcategory,'')subcategory,
  46. isnull(c.subgroup,'')subgroup, qty, month(dodate)do_mth, year(dodate)do_year
  47. from dohdr a
  48. inner join dodtl b on a.dono=b.dono
  49. inner join item c on c.itemno=b.itemno
  50. where dodate between @sdate and @edate
  51. and b.itemno between @fp1 and @fp2
  52. and isnull(c.category,'') between @fp3 and @fp4
  53. and isnull(c.igroup,'') between @fp7 and @fp8
  54. and isnull(c.subcategory,'') between @fp5 and @fp6
  55. and isnull(c.subgroup,'') between @fp9 and @fp10
  56.  
  57. open do_cursor
  58. fetch next from do_cursor into
  59. @itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year
  60.  
  61. -- loop through the retrieve data and insert into report table
  62. while @@FETCH_STATUS = 0
  63. begin
  64.     insert into GTEC1069 (itemno, desp1, category, igroup, subcategory, subgroup, qty, do_mth, do_year)
  65.     values (@itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year)
  66.    
  67.     fetch next from do_cursor into
  68.     @itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year
  69. end
  70.  
  71. close do_cursor
  72. deallocate do_cursor
  73.  
  74. -->> part2: get consign note record
  75. declare consignnote_cursor cursor for
  76. select b.itemno, c.desp1, isnull(c.category,'')category, isnull(c.igroup,'')igroup, isnull(c.subcategory,'')subcategory,
  77. isnull(c.subgroup,'')subgroup, qty, month(consignnotedate)do_mth, year(consignnotedate)do_year
  78. from consignnotehdr a
  79. inner join consignnotedtl b on a.consignnoteno=b.consignnoteno
  80. inner join item c on c.itemno=b.itemno
  81. where consignnotedate between @sdate and @edate
  82. and b.itemno between @fp1 and @fp2
  83. and isnull(c.category,'') between @fp3 and @fp4
  84. and isnull(c.igroup,'') between @fp7 and @fp8
  85. and isnull(c.subcategory,'') between @fp5 and @fp6
  86. and isnull(c.subgroup,'') between @fp9 and @fp10
  87.  
  88. open consignnote_cursor
  89. fetch next from consignnote_cursor into
  90. @itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year
  91.  
  92. -- loop through the retrieve data and insert into report table
  93. while @@FETCH_STATUS = 0
  94. begin
  95.     insert into GTEC1069 (itemno, desp1, category, igroup, subcategory, subgroup, qty, do_mth, do_year)
  96.     values (@itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year)
  97.    
  98.     fetch next from consignnote_cursor into
  99.     @itemno, @desp, @category, @group, @subcategory, @subgroup, @qty, @month, @year
  100. end
  101.  
  102. close consignnote_cursor
  103. deallocate consignnote_cursor
  104.  
  105. SET NOCOUNT OFF
  106. GO
  107.  
  108. SET ANSI_NULLS OFF
  109. GO
  110. SET QUOTED_IDENTIFIER OFF
  111. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement