Q&A about the site for information security professionals
SELECT dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) as test, CAST(DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-2, -1)AS DATE) PreviousSnapshotdate , CAST(DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)AS DATE) CurrentSnapshotDate -- Should be a snapshot date , CAST(DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)AS DATE) StartOfReportingPeriod , CAST((CASE When datepart(dw, dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1))) = 7 Then dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) - 1 When datepart(dw, dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1))) = 1 Then dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) - 2 Else dateadd(d, -datepart(d, DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)), DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) End)AS DATE) previousPricedate , CAST((CASE When datepart(dw, dateadd(d, -datepart(d, getdate()), getdate())) = 7 Then dateadd(d, -datepart(d, getdate()), getdate()) - 1 When datepart(dw, dateadd(d, -datepart(d, getdate()), getdate())) = 1 Then dateadd(d, -datepart(d, getdate()), getdate()) - 2 Else dateadd(d, -datepart(d, getdate()), getdate()) End) AS DATE) ClosingPricedate