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.
| Author |
Topic |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2009-12-18 : 10:15:45
|
| How can I change this procedure to only get the month name out of field:SELECT CONVERT(VARCHAR(20), DowrDate, 7) AS [Month]FROM TSRPTotalsGROUP BY CONVERT(VARCHAR(20), Dowrdate,7)ORDER BY Month DESCThis gives meMonthOct 30, 09Nov 27, 09I would like:October or OctNovember or Nov |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2009-12-18 : 10:18:31
|
| If all your Months are represented by 3 char. abbreviations then simply put - Left(CONVERT(VARCHAR(20), DowrDate, 7),3)If DowrDate is a DateTime field then make a case statement -Case Month(DowrDate) When 1 then 'January' When 2 then 'February'........ When 12 then 'December'End As Month_Name |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-18 : 10:33:21
|
quote: Originally posted by DP978 If all your Months are represented by 3 char. abbreviations then simply put - Left(CONVERT(VARCHAR(20), DowrDate, 7),3)If DowrDate is a DateTime field then make a case statement -Case Month(DowrDate) When 1 then 'January' When 2 then 'February'........ When 12 then 'December'End As Month_Name
You dont need CASESELECT datename(month,date_col) from your_tableMadhivananFailing to plan is Planning to fail |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-12-18 : 10:34:08
|
quote: Originally posted by DP978 If all your Months are represented by 3 char. abbreviations then simply put - Left(CONVERT(VARCHAR(20), DowrDate, 7),3)If DowrDate is a DateTime field then make a case statement -Case Month(DowrDate) When 1 then 'January' When 2 then 'February'........ When 12 then 'December'End As Month_Name
Why you use case statement..what's wrong with this..SELECT DATENAME(MONTH,PARAMETERNAME OR COLUMNNAME)For ExampleSELECT DATENAME(MONTH,GETDATE()) -------------------------R... |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2009-12-18 : 10:51:28
|
| Thanks for your help I used this:SELECT datename(month,DowrDate) AS [Month]FROM TSRPTotalsGROUP BY datename(month,DowrDate)ORDER BY Month DESC |
 |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2009-12-18 : 11:37:44
|
quote: Originally posted by rajdaksha
quote: Originally posted by DP978 If all your Months are represented by 3 char. abbreviations then simply put - Left(CONVERT(VARCHAR(20), DowrDate, 7),3)If DowrDate is a DateTime field then make a case statement -Case Month(DowrDate) When 1 then 'January' When 2 then 'February'........ When 12 then 'December'End As Month_Name
Why you use case statement..what's wrong with this..SELECT DATENAME(MONTH,PARAMETERNAME OR COLUMNNAME)For ExampleSELECT DATENAME(MONTH,GETDATE()) -------------------------R...
Yes sorry I realize this now, my apoligies! I forgot about that function :( As I try and answer these I learn more as well, just takes time to be as good as all of you ;-) |
 |
|
|
|
|
|
|
|