Quantcast
Channel: Questions in topic: "calendar"
Viewing all articles
Browse latest Browse all 26

To print a Calendar in sql server 2008

$
0
0
Hi , Below is the code i am using to get a calendar based on the year and month entered, I want a code like it should accept whichever month i give, like 200BC or 1000 year, is there any other code or below code can be modified??An i should not store those values in a table and retrive data from it. Please help.. declare @datemonth int = 1, @dateYear int = 2014, @startdateofMonthYear date, @EnddateofMonthYear Date Set @startdateofMonthYear=(Select cast(@dateYear as varchar(4)) +'-'+Right('00'+Cast(@datemonth as varchar(2)),2) +'-'+'01') Set @EnddateofMonthYear = (SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@startdateofMonthYear)+1,0))) ;WITH CTE_DatesTable AS ( SELECT @startdateofMonthYear AS [date] UNION ALL SELECT DATEADD(dd, 1, [date]) FROM CTE_DatesTable WHERE DATEADD(dd, 1, [date]) <= @EnddateofMonthYear ) SELECT [DWDateKey]=[date],[DayDate]=datepart(dd,[date]),DATEPART(weekday,[date]), [DayOfWeekName]=datename(dw,[date]),[WeekNumber]=DATEPART( WEEK , [date]),[MonthNumber]=DATEPART( MONTH , [date]),[MonthName]=DATENAME( MONTH , [date]),[Year]=DATEPART(YY,[date]), [QuarterNumber]=DATENAME(quarter, [date]) FROM CTE_DatesTable OPTION (MAXRECURSION 0); go

Viewing all articles
Browse latest Browse all 26

Trending Articles