SQL Server 2005General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I want to convert a month name to month number in sql2005.
For example: My query returns july as 'JUL' and august as 'AUG'.
Now my problem is i have to show 'JUL' as '7' and august as '8' in
I dont want to use case statement. Is there any built in function for this.
Yours was an interesting way of doing this. If I had thought of using CAST, I probably would have done
SELECT DATEPART(mm,CAST(monthname+ ' 1, 1900' AS DATETIME))
I didn't realize you could use a partial data (month and year only) in a CAST expression.
By the by...
Another way to do this would be:
SELECT CHARINDEX(monthname,'XXJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC')/3 AS monthNumber