SQL Server Window Functions (WTD, MTD, YTD, FY) – OVER-clause

Since SQL Server 2012, you’re able to use the OVER-clause for all sorts of things…as seen in my previous post:
https://clinthuijbers.wordpress.com/2015/03/25/sql-server-window-functions-cheat-sheet-over-clause/
(Items like: ‘ROWS … PRECEDING/FOLLOWING…etc.’)


But…let me show you how you could use this to calculate week-to-date (WTD), month-to-date (MTD), year-to-date (YTD) or full-year (FY).
And best of all, it is fast 🙂

Code:
SQL Server window functions WTD MTD YTD FY code


Results:
SQL Server window functions WTD MTD YTD FY results


Download:
SQL Server window functions WTD MTD YTD FY T-SQL code








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