1

Possible Duplicate:
Get a list of dates between two dates using a function

I need to get the result as

1/01/2011
2/01/2011
3/01/2011
4/01/2011
5/01/2011
.
.
.
31/01/2011

I don't want to create a table for this. just want to get this result.

0

1 Answer 1

1

Try this :

  DECLARE @startDate DATETIME;
  SET @startDate = CAST(DATEPART(YYYY,GETDATE()) AS VARCHAR(4)) + CAST(DATEPART(M,GETDATE()) AS VARCHAR(2)) + '01';

  ;WITH CTE(n) AS
  (SELECT 0 UNION ALL SELECT n+1 FROM CTE WHERE n < 30)
  SELECT    DATEADD(dd,n,@startDate)
  FROM  CTE
  WHERE MONTH(DATEADD(dd,n,@startDate)) = MONTH(@startDate);
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.