IF OBJECT_ID ('dbo.Calendar1') IS NOT NULL
DROP PROCEDURE dbo.Calendar1
GO
CREATE PROCEDURE [dbo].[Calendar1]
(
@Month int,
@Year int
)
AS
declare
@startdateofMonthYear date,
@EnddateofMonthYear Date
Set @startdateofMonthYear=(Select cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month 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]),
[DayOfWeekName]=datename(dw,[date]),
[MonthNumber]=DATEPART( MONTH ,[date]),
[MonthName]=DATENAME( MONTH , [date]),
[Year]=DATEPART(YY,[date])
FROM CTE_DatesTable
OPTION (MAXRECURSION 0);
go
HI,
Below is my code, i have used date functions like datepart ,datename andall, without using is there a way to get the output? and i should not store the values in a table and call it also...it is the requirement. In above code i am not storing in a table i am directly accessing, but i have used date function:(
Please help
↧