Quantcast
Viewing all articles
Browse latest Browse all 26

print calendar in sql server 2008

CREATE PROCEDURE [dbo].Calendar1 --4,1991 ( @month int, @Year int ) AS BEGIN declare @startdateofMonthYear date, @EnddateofMonthYear Date if (@month >12) BEGIN Print 'Enter a valid month' END if (@month < 12) BEGIN Set @startdateofMonthYear=(Select cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'01') Set @EnddateofMonthYear = (SELECT case when @month IN (1,3,5,7,8,10,12) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'31' when @month IN(4,6,9,11) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'30' else cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+(CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN '29' else '28' End) End) ;WITH CTE_DatesTable AS ( Select 1 daysint, Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(1 as varchar(2)) as varchar) Calendardates --,@startDayIndex as Level UNION ALL SELECT daysint+1,Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(daysint+1 as varchar(2)) as varchar) Calendardates --,Case when CTE_DatesTable.Level = 7 then 1 else CTE_DatesTable.Level+1 end FROM CTE_DatesTable WHERE daysint<= (SELECT case when @month IN (1,3,5,7,8,10,12) then 31 when @month IN(4,6,9,11) then 30 else (CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN 29 else 28 End) End)-1 ) Select [DWDateKey]=Calendardates, [DayDate]=daysint, [MonthNumber]=@Month, [MonthName]=Case when @month =1 then 'January' when @month =2 then 'February' when @month =3 then 'March' when @month =4 then 'April' when @month =5 then 'May' when @month =6 then 'June' when @month =7 then 'July' when @month =8 then 'August' when @month =9 then 'September' when @month =10 then 'October' when @month =11 then 'November' when @month =12 then 'December' End, [Year]=@Year From CTE_DatesTable END END In the below code i want to get a week name like sunday monday,,without using any date functions like datediff,dateadd,datename without using any of these i should get a weekname. So i got a hint like i know today date 2/13/2014 , 7 days before it was feb 6th that is thursday. Again 7 days before feb 6th is Jan 30th and it is also thursday ,In same way after feb 13th its feb 20th will be thursday. Based on this logic can we get? without using date functions. Only i shud pass month and year as parameter. Is it possible? Plz help

Viewing all articles
Browse latest Browse all 26

Trending Articles