TSQL Month End

WITH DATES AS
(
SELECT GETDATE() DT
UNION ALL
SELECT DT + 1
FROM DATES
WHERE DT < GETDATE() + 3000
)
SELECT CAST(DT AS DATE) AS DATE
, MonthEnd = CASE WHEN DAY(DT + 1) = 1 THEN 1 ELSE 0 END
, QuarterEnd = CASE WHEN DATEPART(quarter, DT + 1) != DATEPART(quarter, DT) THEN 1 ELSE 0 END
, YearEnd = CASE WHEN YEAR(DT + 1) != YEAR(DT) THEN 1 ELSE 0 END
FROM DATES
OPTION (MAXRECURSION 3000)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s