Guest User

Untitled

a guest
Jan 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Week Ending 21/01/2018
  2. Week Ending 28/01/2018
  3. Week Ending 04/02/2018
  4. Week Ending 11/02/2018
  5. Week Ending 18/02/2018
  6. Week Ending 25/02/2018
  7. Week Ending 04/03/2018
  8.  
  9. Week Ending 22/01/2018
  10. Week Ending 29/01/2018
  11. Week Ending 05/02/2018
  12. Week Ending 12/02/2018
  13. Week Ending 19/02/2018
  14. Week Ending 26/02/2018
  15. Week Ending 05/03/2018
  16.  
  17. SET @dteStartDate = CAST(@prmStartDate As smalldatetime)
  18. SET @dteEndDate = CAST(@prmEndDate As smalldatetime)
  19.  
  20. DECLARE @MyTempTable TABLE (
  21. [tmpDate] [smalldatetime],
  22. [NumReferrals] [int] NULL
  23. )
  24.  
  25. DECLARE @dteCurrent AS SMALLDATETIME
  26. DECLARE @NumReferrals AS INT
  27.  
  28.  
  29. SELECT @dteCurrent = dbo.fnGetEndOfWeek(@dteStartDate)
  30.  
  31.  
  32. WHILE @dteCurrent <= dbo.fnGetEndOfWeek(@dteEndDate)
  33. BEGIN
  34. --SELECT FROM DATA
  35. INSERT INTO @MyTempTable (tmpDate, NumReferrals) VALUES (@dteCurrent, @NumReferrals)
  36. SET @dteCurrent = DATEADD(Week, 1, @dteCurrent)
  37. END
  38.  
  39.  
  40. SELECT NumReferrals as Referrals,
  41. 'Week Ending ' + convert(nvarchar, tmpDate, 103) AS WeekEnding
  42.  
  43. FROM @MyTempTable
  44.  
  45. CREATE FUNCTION dbo.fnGetEndOfWeek
  46. (
  47. @prmInputDate smalldatetime
  48.  
  49. )
  50.  
  51. BEGIN
  52. Declare @AddNumOfDay INT
  53.  
  54. -- If input date is not Sunday, move it foward to Sunday
  55. -- 1 Sunday
  56. -- 2 Monday
  57. -- ...
  58. -- 7 Saturday
  59.  
  60. SELECT @AddNumOfDay = CASE (DATEPART(WEEKDAY, @prmInputDate))
  61. WHEN '2' THEN '6'
  62. WHEN '3' THEN '5'
  63. WHEN '4' THEN '4'
  64. WHEN '5' THEN '3'
  65. WHEN '6' THEN '2'
  66. WHEN '7' THEN '1'
  67. WHEN '1' THEN '0'
  68. END
  69.  
  70. RETURN DATEADD(d,@AddNumOfDay,@prmInputDate)
  71. END
  72.  
  73. Dim dtSeriesData As New Data.DataTable
  74.  
  75. Using cmdGetSeries As SqlCommand = conLocal.CreateCommand()
  76. Using sqlSeries As SqlDataAdapter = New SqlDataAdapter()
  77.  
  78. cmdGetSeries.CommandType = Data.CommandType.StoredProcedure
  79. cmdGetSeries.CommandText = sp
  80. For Each param As SqlParameter In sqlParams
  81. If Not param Is Nothing Then
  82. cmdGetSeries.Parameters.Add(param)
  83. End If
  84. Next
  85.  
  86. Using dr As System.Data.Common.DbDataReader = cmdGetSeries.ExecuteReader()
  87. dtSeriesData.Load(dr) *
  88. End Using
  89. End Using
  90. cmdGetSeries.Parameters.Clear()
  91. End Using
  92.  
  93. exec spGetGraphReferralsbyWeekAll @prmStartDate='18 Jan 2018',@prmEndDate='01 Mar 2018'
  94.  
  95. Week Ending 21/01/2018
  96. Week Ending 28/01/2018
  97. Week Ending 04/02/2018
  98. Week Ending 11/02/2018
  99. Week Ending 18/02/2018
  100. Week Ending 25/02/2018
  101. Week Ending 04/03/2018
  102.  
  103. Week Ending 22/01/2018
Add Comment
Please, Sign In to add comment