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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Date format

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-05-31 : 03:11:35
Hi All,

I need to convert the below format data to "mmm-yyyy" ? How to do this ?
input output
January 2010 > Jan-2010
January 2010 > Jan 2010
February 2010 > Feb 2010
February 2010 > Feb-2010
March 2010 etc
March 2010
April 2010
April 2010
May 2010
May 2010
June 2010
June 2010
July 2010
July 2010
August 2010
August 2010

Thanks,
Gangadhara MS
SQL Developer and DBA

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-31 : 05:06:54
[code]
SELECT
left(datename(month, convert(datetime, '01 ' + col)), 3)
+ '-'
+ datename(year, convert(datetime, '01 ' + col))
[/code]


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-05-31 : 08:55:31
1 Always use proper DATETIME datatype to store dates
2 Let the front end application do the formation

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-05-31 : 23:11:10
I am getting this error.
The data types varchar and ntext are incompatible in the add operator.

The column which i am operating will be ntext (ex:August 2010) and this can't be changed as it has other impact

Pls help me .


Thanks,
Gangadhara MS
SQL Developer and DBA
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-01 : 11:10:56
select left(ast(col as nvarchar(max)),3)+'-'+left(ast(col as nvarchar(max)),4) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -