Guest User

Untitled

a guest
Jan 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. INSERT INTO [SupportTracker].[dbo].[DashboardRecords]
  2. SELECT [bg_id]
  3. ,[bg_short_desc]
  4. ,[bg_reported_date]
  5. ,[bg_status_updated_date]
  6. ,[us_firstname]
  7. ,[us_lastname]
  8. ,[LastUpdatedUserFirstname]
  9. ,[LastUpdatedUserLastname]
  10. ,[st_name]
  11. ,[pr_name]
  12. ,[ct_name]
  13. ,[pj_name]
  14. ,[AssignedUserFirstname]
  15. ,[AssignedUserLastname]
  16. ,[bg_project]
  17. ,[no_of_hours]
  18. ,[BugType]
  19. ,[SubType]
  20. ,[Device]
  21. ,[pj_parent_id]
  22. FROM [SupportTracker].[dbo].[ViewIssueListwBugTypeNDevice]
  23. WHERE
  24. bg_reported_date between '2012-12-01 00:00:00.000' AND '2012-12-31 23:59:59.999'
  25. AND bg_id NOT IN (SELECT bg_id FROM [SupportTracker].[dbo].[DashboardRecords])
  26. ORDER BY bg_reported_date ASC
  27.  
  28. SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0);
  29.  
  30. SELECT DATEADD(MONTH, 1+DATEDIFF(MONTH, 0, GETDATE()), 0);
  31.  
  32. SELECT DATEADD(MONTH, 1+DATEDIFF(MONTH, 0, DATEADD(DAY, -1, GETDATE())), 0);
  33.  
  34. ...
  35. FROM SupportTracker.dbo.ViewIssueListwBugTypeNDevice AS v
  36. WHERE NOT EXISTS
  37. (
  38. SELECT 1 FROM SupportTracker.dbo.DashboardRecords
  39. WHERE bg_id = v.bg_id
  40. )
  41. AND v.bg_reported_date >= DATEADD(MONTH, 0, DATEDIFF(MONTH, 0, DATEADD(DAY, -1, GETDATE()))
  42. AND v.bg_reported_date < DATEADD(MONTH, 1, DATEDIFF(MONTH, 0, DATEADD(DAY, -1, GETDATE()));
  43.  
  44. @Month DATE = NULL
  45. ...
  46.  
  47. SET @Month = DATEADD(MONTH, 0, DATEDIFF(MONTH, 0, COALESCE(@Month,
  48. DATEADD(DAY, -1, GETDATE())));
  49.  
  50. ...
  51. FROM SupportTracker.dbo.ViewIssueListwBugTypeNDevice AS v
  52. WHERE NOT EXISTS
  53. (
  54. SELECT 1 FROM SupportTracker.dbo.DashboardRecords
  55. WHERE bg_id = v.bg_id
  56. )
  57. AND v.bg_reported_date >= @Month
  58. AND v.bg_reported_date < DATEADD(MONTH, 1, @Month);
  59.  
  60. SELECT FirstOfThisMonth = DATEADD(DAY, 1-DAY(GETDATE()), CONVERT(date, GETDATE()));
  61.  
  62. DECLARE @MonthStart DATETIME
  63. DECLARE @Date DATETIME
  64. DECLARE @next DATETIME
  65. -- create the required date. because today is the 21st i subtracted month.
  66. -- since you're running the job on the first day of the new month,
  67. -- you may want to change MONTH to DAY. however, if the job fails that change
  68. -- that may cause you some problems
  69. SET @Date = DATEADD(MONTH,-1,DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0))
  70.  
  71. -- get the first day of the month of the date specified
  72. SET @MonthStart = DATEADD(DAY, 1, @Date - DAY(@Date) + 1) -1
  73.  
  74. -- get the first day of next month
  75. SET @Next = DATEADD(MONTH,1,@MonthStart)
  76.  
  77. -- prove to yourself that these dates are correct (sanity check)
  78. SELECT @MonthStart, @next
  79.  
  80. INSERT INTO [SupportTracker].[dbo].[DashboardRecords]
  81. SELECT [bg_id]
  82. ,[bg_short_desc]
  83. ,[bg_reported_date]
  84. ,[bg_status_updated_date]
  85. ,[us_firstname]
  86. ,[us_lastname]
  87. ,[LastUpdatedUserFirstname]
  88. ,[LastUpdatedUserLastname]
  89. ,[st_name]
  90. ,[pr_name]
  91. ,[ct_name]
  92. ,[pj_name]
  93. ,[AssignedUserFirstname]
  94. ,[AssignedUserLastname]
  95. ,[bg_project]
  96. ,[no_of_hours]
  97. ,[BugType]
  98. ,[SubType]
  99. ,[Device]
  100. ,[pj_parent_id]
  101. FROM [SupportTracker].[dbo].[ViewIssueListwBugTypeNDevice] b
  102. LEFT JOIN [SupportTracker].[dbo].[DashboardRecords] d
  103. ON b.bg_id = d.bg_id
  104. WHERE b.bg_reported_date >= @MonthStart and b.bg_reported_date < @Next
  105. AND d.[bg_short_desc] IS NULL
  106.  
  107. INSERT INTO [SupportTracker].[dbo].[DashboardRecords]
  108.  
  109. SELECT [bg_id]
  110. ,[bg_short_desc]
  111. ,[bg_reported_date]
  112. ,[bg_status_updated_date]
  113. ,[us_firstname]
  114. ,[us_lastname]
  115. ,[LastUpdatedUserFirstname]
  116. ,[LastUpdatedUserLastname]
  117. ,[st_name]
  118. ,[pr_name]
  119. ,[ct_name]
  120. ,[pj_name]
  121. ,[AssignedUserFirstname]
  122. ,[AssignedUserLastname]
  123. ,[bg_project]
  124. ,[no_of_hours]
  125. ,[BugType]
  126. ,[SubType]
  127. ,[Device]
  128. ,[pj_parent_id]
  129. FROM [SupportTracker].[dbo].[ViewIssueListwBugTypeNDevice] b
  130. WHERE b.bg_reported_date >= @MonthStart and b.bg_reported_date < @Next
  131. AND NOT EXISTS (SELECT 1 FROM [SupportTracker].[dbo].[DashboardRecords] d
  132. WHERE b.bg_id = d.bg_id);
Add Comment
Please, Sign In to add comment