DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

SELECT  
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

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results