I recently required a query for a report which listed the remaining business days for this year, including the current day. I immediately thought of using spt_values count table.
The spt_values System Table inside the master database is an ideal table to use when you need to use numbers in your query. This system table is used internally by sql server for various operations. For eg: The query shown here generates values from 0 to 2047
SELECT number from master..spt_values
Let’s use this system table to list the remaining business days for this year:
AND DATENAME(WEEKDAY, DATEADD(DAY, number, DATEDIFF(DAY, '19000101', GETDATE())))
NOT IN ('Saturday', 'Sunday')
To Find the Business Days in a Quarter, check this query of mine
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|