DZone

One of my applications displays tables with some calculations about users working time. This is for corporate reporting. For this table, I needed a way to find how many weekends days are in given month. As most of the calculation work is done in SQL Server stored procedures, I decided to keep stuff there and found a way how to get weekend days with common table expression.

I looked for different options and in a given solution, it seemed the best idea to go with second solution answer from MSDN forum post on how to find the weekend days in SQL Server 2008. The idea is simple: we create common table expressions (CTE) for given year dates and select out only those where the name of week day is Saturday or Sunday.

Source: DZone