Thursday, July 03, 2008

3 Character Month abbreviation to equivalent number

Easy way to convert the 3 character month abbreviation to equivalent month number -

DECLARE @MyTable table
( RowID int IDENTITY,
ShortMonth char(3)
)

INSERT INTO @MyTable VALUES ( 'Aug' )
INSERT INTO @MyTable VALUES ( 'Feb' )

SELECT (( patindex( ('%,' + ShortMonth + '%' ),',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,' ) / 4 ) + 1 ) FROM @MyTable

Ref: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3569811&SiteID=1

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home