Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column with Monthstart date and Monthend date

Author  Topic 

Shubhanshu
Starting Member

8 Posts

Posted - 2012-03-14 : 02:04:27
Hi everyone
Please help me ...I want to generate the column with mentioned below format..

2012-01-01
2012-01-31
2012-02-01
2012-02-29
|
|
|2012-12-31

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-14 : 02:08:12
you can make use of F_TABLE_DATE
from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519&SearchTerms=F_TABLE_DATE


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-03-14 : 05:10:35
[code]DECLARE @Year SMALLINT

SET @Year = 2012

SELECT DATEADD(MONTH, 12 * @Year - 22800 + Number, '19000101')
FROM master.dbo.spt_values
WHERE Type = 'P'
AND Number BETWEEN 0 AND 11

UNION ALL

SELECT DATEADD(MONTH, 12 * @Year - 22800 + Number, '19000131')
FROM master.dbo.spt_values
WHERE Type = 'P'
AND Number BETWEEN 0 AND 11[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -