How to Query SQL server for T-SQL Calendar using GetFullMonth using Pivot

After listing sql calendar date values in a month as rows, we need to display them now in a format similar to frequently used in printed calendars.
The day names are listed as column names and dates are shown under the related columns.
The first solution is supplied by Plamen Ratchev from SQLStudio.com using the t-sql PIVOT. Since I liked the t-sql code he coded much I want to share it with you here.
SELECT
[Sunday],
[Monday],
[Tuesday],
[Wednesday],
[Thursday],
[Friday],
[Saturday]
FROM
(
SELECT
DATEPART(WEEK, [date]) AS week_number,
[date],
[days]
FROM dbo.getFullmonth('20080229')
) AS Dates
PIVOT
(
MIN([date])
FOR
[days] IN (
[Sunday],
[Monday],
[Tuesday],
[Wednesday],
[Thursday],
[Friday],
[Saturday]
)
) AS Pivots
And the output of this sql pivot statement will return the following result set as output which is displaying sql dates in a calendar format.
t-sql pivot command to format dates as calendar

Popular posts from this blog

Using SSRS web services to render a report as a PDF

Integrating MIGS eGate Payment gateway using C# for Oz businesses (Server-Hosted Payment method)

Creating a Link Server to MYSQL from MSSQL