-2

I want to fetch date series for input month and year in sql server 2005.

ex: Month jan 
    year 2014

it should display all dates for Jan 2014.

sus123
  • 3
  • 2
  • There is no such thing as "SQL 2005". I replaced that with "SQL **Server** 2005" (which is the name of an existing DBMS) –  Jul 10 '14 at 06:43

1 Answers1

0

Please try using CTE:

DECLARE @Month nvarchar(3), @Year nvarchar(4)
SET @Month='Jan'
SET @Year=2014

DECLARE @RepMonth as datetime
SET @RepMonth = '01-'+@Month+'-'+@Year;

WITH DayList (DayDate) AS
(
    SELECT @RepMonth
    UNION ALL
    SELECT DATEADD(d, 1, DayDate)
    FROM DayList
    WHERE (DayDate < DATEADD(d, -1, DATEADD(m, 1, @RepMonth)))
)
SELECT *
FROM DayList
TechDo
  • 18,398
  • 3
  • 51
  • 64
  • http://stackoverflow.com/questions/1378593/get-a-list-of-dates-between-two-dates-using-a-function – sumit Jul 10 '14 at 06:39