Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.81 KB | None | 0 0
  1. USE [BELBaseline]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[sp_DMS_BaselineMonthly] Script Date: 10/22/2019 2:23:17 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9.  
  10.  
  11. -- =============================================
  12. -- Author: Dinh Hoang Lam
  13. -- Create date: 2015/04/02
  14. -- Description:
  15. -- =============================================
  16. -- EXEC sp_DMS_BaselineMonthly 4,8, 2016, 1
  17. ALTER PROCEDURE [dbo].[sp_DMS_BaselineMonthly]
  18. @CompanyID INT
  19. , @Month INT
  20. , @Year INT
  21. , @DistributorID VARCHAR(MAX)
  22. AS
  23. BEGIN
  24. SET NOCOUNT ON
  25.  
  26. DECLARE @_CompanyID INT = @CompanyID
  27. DECLARE @_Month INT = @Month
  28. DECLARE @_Year INT = @Year
  29. DECLARE @_DistributorID VARCHAR(MAX) = NULLIF(LTRIM(RTRIM(@DistributorID)), '')
  30. DECLARE @_MonthID CHAR(6) = RIGHT('0' + CONVERT(VARCHAR(2), @_Month), 2) + CONVERT(VARCHAR(4), @_Year)
  31. DECLARE @_FirstDayOfMonth DATETIME = CONVERT(DATETIME, CONVERT(VARCHAR(4), @_Year) + '/' + CONVERT(VARCHAR(2), @_Month) + '/1')
  32. DECLARE @_LastDayOfMonth DATETIME = DATEADD(dd, -1, DATEADD(mm, 1, @_FirstDayOfMonth))
  33. DECLARE @_LastDayBaselineOfMonth DATETIME
  34. DECLARE @_MonthlyBaseline INT
  35.  
  36. SELECT @_MonthlyBaseline = MonthlyBaseline FROM BELDMS..DMSBaselineConfig WHERE CompanyID = @_CompanyID
  37. SET @_LastDayBaselineOfMonth = DATEADD(dd, @_MonthlyBaseline, @_LastDayOfMonth)
  38. IF DATEPART(dw, @_LastDayBaselineOfMonth) = 1
  39. SET @_LastDayBaselineOfMonth = DATEADD(dd, 1, @_LastDayBaselineOfMonth)
  40. SET @_LastDayBaselineOfMonth = GETDATE()
  41. ---- Baseline Transaction Data
  42.  
  43. DECLARE @_CheckDate datetime = getdate()
  44. declare @StartTime datetime , @EndTime datetime;
  45. declare @StartRowCount float , @EndRowCount float , @RowCountNumber float;
  46. DECLARE @Message NVARCHAR(MAX) , @Parameter nvarchar(max);
  47. SET @Message='';
  48. DECLARE @Error NVARCHAR(MAX);
  49. ---- Nếu tháng trước chưa được chốt baseline tháng thì set ngày baseline từ tháng trước.
  50. IF NOT EXISTS (SELECT TOP 1 * FROM dbo.DMSBLMonthlyHistory WHERE CompanyID = @_CompanyID AND MonthID = @_MonthID)
  51. BEGIN
  52. INSERT INTO dbo.DMSBLMonthlyHistory(BaselineDate, CompanyID, MonthID ) VALUES(GETDATE(), @_CompanyID, @_MonthID)
  53. UPDATE BELDMS..DMSBaselineClosedDate SET ClosedDate = @_LastDayOfMonth WHERE CompanyID = @_CompanyID
  54. END
  55. ELSE
  56. UPDATE dbo.DMSBLMonthlyHistory SET BaselineDate = GETDATE() WHERE CompanyID = @_CompanyID AND MonthID = @_MonthID
  57.  
  58. --Start Baseline Month
  59. begin try
  60. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  61. set @StartTime = getdate();
  62. set @StartRowCount = (select count(1) from DMSBLMCPHistory)
  63. EXEC dbo.sp_DMS_Baseline_MCPMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  64. set @EndTime = GETDATE();
  65. set @EndRowCount = (select count(1) from DMSBLMCPHistory)
  66. set @RowCountNumber = @EndRowCount - @StartRowCount
  67. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_MCPMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  68. end try
  69. begin catch
  70. IF(ERROR_MESSAGE() IS NOT NULL)
  71. BEGIN
  72. SET @Error=ERROR_MESSAGE();
  73. SET @Message= @Message+' - store sp_DMS_Baseline_MCPMonthly failed: ' +@Error + '<br/>';
  74. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_MCPMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  75. END
  76. end catch
  77.  
  78. begin try
  79. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayBaselineOfMonth=' + convert(nvarchar(20),@_LastDayBaselineOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  80. set @StartTime = getdate();
  81. set @StartRowCount = (select count(1) from DMSBLRawSalesHistory)
  82. EXEC dbo.sp_DMS_Baseline_RawSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayBaselineOfMonth, @_DistributorID
  83. set @EndTime = GETDATE();
  84. set @EndRowCount = (select count(1) from DMSBLRawSalesHistory)
  85. set @RowCountNumber = @EndRowCount - @StartRowCount
  86. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_RawSalesMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  87. end try
  88. begin catch
  89. IF(ERROR_MESSAGE() IS NOT NULL)
  90. BEGIN
  91. SET @Error=ERROR_MESSAGE();
  92. SET @Message= @Message+' - store sp_DMS_Baseline_RawSalesMonthly failed: ' +@Error + '<br/>';
  93. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_RawSalesMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  94. END
  95. end catch
  96.  
  97. begin try
  98. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayBaselineOfMonth=' + convert(nvarchar(20),@_LastDayBaselineOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  99. set @StartTime = getdate();
  100. set @StartRowCount = (select count(1) from DMSBLIncompleteRawSalesHistory)
  101. EXEC dbo.sp_DMS_Baseline_IncompleteRawSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayBaselineOfMonth, @_DistributorID
  102. set @EndTime = GETDATE();
  103. set @EndRowCount = (select count(1) from DMSBLIncompleteRawSalesHistory)
  104. set @RowCountNumber = @EndRowCount - @StartRowCount
  105. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_IncompleteRawSalesMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  106. end try
  107. begin catch
  108. IF(ERROR_MESSAGE() IS NOT NULL)
  109. BEGIN
  110. SET @Error=ERROR_MESSAGE();
  111. SET @Message= @Message+' - store sp_DMS_Baseline_IncompleteRawSalesMonthly failed: ' +@Error + '<br/>';
  112. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_IncompleteRawSalesMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  113. END
  114. end catch
  115.  
  116. begin try
  117. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  118. set @StartTime = getdate();
  119. set @StartRowCount = (select count(1) from DMSBLPromotionDetailHistory)
  120. EXEC dbo.sp_DMS_Baseline_PromotionDetailMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  121. set @EndTime = GETDATE();
  122. set @EndRowCount = (select count(1) from DMSBLPromotionDetailHistory)
  123. set @RowCountNumber = @EndRowCount - @StartRowCount
  124. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_PromotionDetailMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  125. end try
  126. begin catch
  127. IF(ERROR_MESSAGE() IS NOT NULL)
  128. BEGIN
  129. SET @Error=ERROR_MESSAGE();
  130. SET @Message= @Message+' - store sp_DMS_Baseline_PromotionDetailMonthly failed: ' +@Error + '<br/>';
  131. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_PromotionDetailMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  132. END
  133. end catch
  134.  
  135. begin try
  136. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  137. set @StartTime = getdate();
  138. set @StartRowCount = (select count(1) from DMSBLPromotionDetailFullHistory)
  139. EXEC dbo.sp_DMS_Baseline_PromotionDetailFullMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  140. set @EndTime = GETDATE();
  141. set @EndRowCount = (select count(1) from DMSBLPromotionDetailFullHistory)
  142. set @RowCountNumber = @EndRowCount - @StartRowCount
  143. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_PromotionDetailFullMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  144. end try
  145. begin catch
  146. IF(ERROR_MESSAGE() IS NOT NULL)
  147. BEGIN
  148. SET @Error=ERROR_MESSAGE();
  149. SET @Message= @Message+' - store sp_DMS_Baseline_PromotionDetailFullMonthly failed: ' +@Error + '<br/>';
  150. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_PromotionDetailFullMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  151. END
  152. end catch
  153.  
  154. begin try
  155. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  156. set @StartTime = getdate();
  157. set @StartRowCount = (select count(1) from DMSBLSalesHistory) + (select count(1) from DMSBLSalesHistory)
  158. EXEC dbo.sp_DMS_Baseline_SalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  159. set @EndTime = GETDATE();
  160. set @EndRowCount = (select count(1) from DMSBLSalesHistory)+ (select count(1) from DMSBLSalesHistory)
  161. set @RowCountNumber = @EndRowCount - @StartRowCount
  162. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_SalesMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  163. end try
  164. begin catch
  165. IF(ERROR_MESSAGE() IS NOT NULL)
  166. BEGIN
  167. SET @Error=ERROR_MESSAGE();
  168. SET @Message= @Message+' - store sp_DMS_Baseline_SalesMonthly failed: ' +@Error + '<br/>';
  169. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_SalesMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  170. END
  171. end catch
  172.  
  173. begin try
  174. set @Parameter = '@_CompanyID = 3,@_Year=' + convert(nvarchar(20),@_Year) + ',@_Year=' + convert(nvarchar(20),@_Year) + ',@_Month=' + convert(nvarchar(20),@_Month) + ',@_Month=' + convert(nvarchar(20),@_Month) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  175. set @StartTime = getdate();
  176. set @StartRowCount = (select count(1) from DMSBLDistributorSKUSales)
  177. EXEC dbo.sp_DMS_Baseline_DistributorSKUSales @_CompanyID, @_Year, @_Year, @_Month, @_Month, @_DistributorID
  178. set @EndTime = GETDATE();
  179. set @StartRowCount = (select count(1) from DMSBLDistributorSKUSales)
  180. set @RowCountNumber = @EndRowCount - @StartRowCount
  181. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSKUSales' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  182. end try
  183. begin catch
  184. IF(ERROR_MESSAGE() IS NOT NULL)
  185. BEGIN
  186. SET @Error=ERROR_MESSAGE();
  187. SET @Message= @Message+' - store sp_DMS_Baseline_DistributorSKUSales failed: ' +@Error + '<br/>';
  188. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSKUSales' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  189. END
  190. end catch
  191.  
  192. begin try
  193. set @Parameter = '@_CompanyID = 3,@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth)
  194. set @StartTime = getdate();
  195. set @StartRowCount = (select count(1) from DMSBLObjectKPITemp) + (select count(1) from DMSBLSalesObjectRawDataTemp) + (select count(1) from DMSBLKPI)
  196. EXEC dbo.sp_DMS_Baseline_KPI @_CompanyID, @_LastDayOfMonth
  197. set @EndTime = GETDATE();
  198. set @StartRowCount = (select count(1) from DMSBLObjectKPITemp) + (select count(1) from DMSBLSalesObjectRawDataTemp) + (select count(1) from DMSBLKPI)
  199. set @RowCountNumber = @EndRowCount - @StartRowCount
  200. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_KPI' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  201. end try
  202. begin catch
  203. IF(ERROR_MESSAGE() IS NOT NULL)
  204. BEGIN
  205. SET @Error=ERROR_MESSAGE();
  206. SET @Message= @Message+' - store sp_DMS_Baseline_KPI failed: ' +@Error + '<br/>';
  207. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_KPI' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  208. END
  209. end catch
  210.  
  211. begin try
  212. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  213. set @StartTime = getdate();
  214. set @StartRowCount = (select count(1) from DMSBLRouteSalesHistory)
  215. EXEC dbo.sp_DMS_Baseline_RouteSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  216. set @EndTime = GETDATE();
  217. set @StartRowCount = (select count(1) from DMSBLRouteSalesHistory)
  218. set @RowCountNumber = @EndRowCount - @StartRowCount
  219. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_RouteSalesMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  220. end try
  221. begin catch
  222. IF(ERROR_MESSAGE() IS NOT NULL)
  223. BEGIN
  224. SET @Error=ERROR_MESSAGE();
  225. SET @Message= @Message+' - store sp_DMS_Baseline_RouteSalesMonthly failed: ' +@Error + '<br/>';
  226. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_RouteSalesMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  227. END
  228. end catch
  229.  
  230. begin try
  231. set @Parameter = '@_CompanyID = 3,@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  232. set @StartTime = getdate();
  233. set @StartRowCount = (select count(1) from DMSBLDistributorSales)
  234. EXEC dbo.sp_DMS_Baseline_DistributorSales @_CompanyID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  235. set @EndTime = GETDATE();
  236. set @StartRowCount = (select count(1) from DMSBLDistributorSales)
  237. set @RowCountNumber = @EndRowCount - @StartRowCount
  238. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSales' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  239. end try
  240. begin catch
  241. IF(ERROR_MESSAGE() IS NOT NULL)
  242. BEGIN
  243. SET @Error=ERROR_MESSAGE();
  244. SET @Message= @Message+' - store sp_DMS_Baseline_DistributorSales failed: ' +@Error + '<br/>';
  245. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSales' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  246. END
  247. end catch
  248.  
  249. begin try
  250. set @Parameter = '@_CompanyID = 3,@_Month=' + convert(nvarchar(20),@_Month) + ',@_Year=' + convert(nvarchar(20),@_Year)
  251. set @StartTime = getdate();
  252. set @StartRowCount = (select count(1) from DMSBLDistributorSystem)
  253. EXEC dbo.sp_DMS_Baseline_DistributorSystem @_CompanyID, @_Month, @_Year
  254. set @EndTime = GETDATE();
  255. set @StartRowCount = (select count(1) from DMSBLDistributorSystem)
  256. set @RowCountNumber = @EndRowCount - @StartRowCount
  257. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSystem' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  258. end try
  259. begin catch
  260. IF(ERROR_MESSAGE() IS NOT NULL)
  261. BEGIN
  262. SET @Error=ERROR_MESSAGE();
  263. SET @Message= @Message+' - store sp_DMS_Baseline_DistributorSystem failed: ' +@Error + '<br/>';
  264. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSystem' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  265. END
  266. end catch
  267.  
  268. begin try
  269. set @Parameter = '@_CompanyID = 3,@_Month=' + convert(nvarchar(20),@_Month) + ',@_Year=' + convert(nvarchar(20),@_Year)
  270. set @StartTime = getdate();
  271. set @StartRowCount = (select count(1) from DMSBLDistributorSystemByCustomer)
  272. EXEC dbo.sp_DMS_Baseline_DistributorSystemByCustomer @_CompanyID, @_Month, @_Year
  273. set @EndTime = GETDATE();
  274. set @StartRowCount = (select count(1) from DMSBLDistributorSystemByCustomer)
  275. set @RowCountNumber = @EndRowCount - @StartRowCount
  276. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSystemByCustomer' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  277. end try
  278. begin catch
  279. IF(ERROR_MESSAGE() IS NOT NULL)
  280. BEGIN
  281. SET @Error=ERROR_MESSAGE();
  282. SET @Message= @Message+' - store sp_DMS_Baseline_DistributorSystemByCustomer failed: ' +@Error + '<br/>';
  283. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_DistributorSystemByCustomer' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  284. END
  285. end catch
  286.  
  287. begin try
  288. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  289. set @StartTime = getdate();
  290. set @StartRowCount = (select count(1) from BELDMS..DMSInventoryStockHistory)
  291. EXEC BELDMS..sp_DMS_InsertInventoryStockMonthly @_CompanyID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  292. set @EndTime = GETDATE();
  293. set @StartRowCount = (select count(1) from BELDMS..DMSInventoryStockHistory)
  294. set @RowCountNumber = @EndRowCount - @StartRowCount
  295. EXEC dbo.spInsertHistory 'sp_DMS_InsertInventoryStockMonthly' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  296. end try
  297. begin catch
  298. IF(ERROR_MESSAGE() IS NOT NULL)
  299. BEGIN
  300. SET @Error=ERROR_MESSAGE();
  301. SET @Message= @Message+' - store sp_DMS_InsertInventoryStockMonthly failed: ' +@Error + '<br/>';
  302. EXEC dbo.spInsertHistory 'sp_DMS_InsertInventoryStockMonthly' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  303. END
  304. end catch
  305. begin try
  306. set @Parameter = '@_CompanyID = 3,@_MonthID=' + convert(nvarchar(20),@_MonthID) + ',@_FirstDayOfMonth=' + convert(nvarchar(20),@_FirstDayOfMonth) + ',@_LastDayOfMonth=' + convert(nvarchar(20),@_LastDayOfMonth) + ',@_DistributorID='+Isnull(@_DistributorID,'')
  307. set @StartTime = getdate();
  308. set @StartRowCount = (select count(1) from BELDMS..DMSInventoryStockHistory)
  309. EXEC sp_DMS_Baseline_ProgramTracking @_CompanyID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  310. set @EndTime = GETDATE();
  311. set @StartRowCount = (select count(1) from BELDMS..DMSInventoryStockHistory)
  312. set @RowCountNumber = @EndRowCount - @StartRowCount
  313. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_ProgramTracking' , @Parameter, 1,'' ,@StartTime , @EndTime,@RowCountNumber
  314. end try
  315. begin catch
  316. IF(ERROR_MESSAGE() IS NOT NULL)
  317. BEGIN
  318. SET @Error=ERROR_MESSAGE();
  319. SET @Message= @Message+' - store sp_DMS_InsertInventoryStockMonthly failed: ' +@Error + '<br/>';
  320. EXEC dbo.spInsertHistory 'sp_DMS_Baseline_ProgramTracking' , @Parameter, 0,@Message, @StartTime , @EndTime,@RowCountNumber;
  321. END
  322. end catch
  323. --EXEC dbo.sp_DMS_Baseline_MCPMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  324.  
  325. --EXEC dbo.sp_DMS_Baseline_RawSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayBaselineOfMonth, @_DistributorID
  326.  
  327. --EXEC dbo.sp_DMS_Baseline_IncompleteRawSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayBaselineOfMonth, @_DistributorID
  328.  
  329. --EXEC dbo.sp_DMS_Baseline_PromotionDetailMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  330.  
  331. --EXEC dbo.sp_DMS_Baseline_PromotionDetailFullMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  332.  
  333. --EXEC dbo.sp_DMS_Baseline_SalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  334.  
  335. --EXEC dbo.sp_DMS_Baseline_DistributorSKUSales @_CompanyID, @_Year, @_Year, @_Month, @_Month, @_DistributorID
  336.  
  337. --EXEC dbo.sp_DMS_Baseline_KPI @_CompanyID, @_LastDayOfMonth
  338.  
  339. --EXEC dbo.sp_DMS_Baseline_RouteSalesMonthly @_CompanyID, @_MonthID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  340.  
  341. --EXEC dbo.sp_DMS_Baseline_DistributorSales @_CompanyID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  342.  
  343. --EXEC dbo.sp_DMS_Baseline_DistributorSystem @_CompanyID, @_Month, @_Year
  344.  
  345. --EXEC dbo.sp_DMS_Baseline_DistributorSystemByCustomer @_CompanyID, @_Month, @_Year
  346.  
  347. --EXEC BELDMS..sp_DMS_InsertInventoryStockMonthly @_CompanyID, @_FirstDayOfMonth, @_LastDayOfMonth, @_DistributorID
  348.  
  349.  
  350.  
  351. exec BELDMS..pp_DMS_L2_SendInforAfterBaseline @CompanyID,@_CheckDate,@_FirstDayOfMonth,@_LastDayOfMonth
  352. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement