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 |
|
shantanu88d
Starting Member
35 Posts |
Posted - 2011-04-15 : 07:17:05
|
| Hi, I have a table having column which is going to contain date in format of MM YYYY. How can I order this table on basis of this dateE.g I am getting this tablebill_for bill_paid service_tax-------------------- -------------------------------- ------------------------------------Apr 2011 2000.00 20.00Feb 2011 400.00 4.00Jan 2011 2000.00 20.00Mar 2011 6300.00 90.33I want it to bebill_for bill_paid service_tax-------------------- -------------------------------- ------------------------------------Jan 2011 2000.00 20.00Feb 2011 400.00 4.00Mar 2011 2000.00 20.00Apr 2011 6300.00 90.33Please HELP !! |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-04-15 : 07:22:19
|
You can add the order by clause after casting it to datetime as in:order by cast(bill_for as datetime) The string 'Apr 2011' will get converted to the date of April 1, 2011.This assumes that the bill_for column has the 3 character abbreviation for the month part. If it has values that are not well-defined for example, "Sept 2011" then you will need to do more work. |
 |
|
|
shantanu88d
Starting Member
35 Posts |
Posted - 2011-04-15 : 07:38:45
|
| WOW, that was amazing !!! Didnt knw that sql server converts strings like apr 2011 into datetime values ! Thank you so much :) |
 |
|
|
|
|
|