February 3, 2010 at 6:14 am
Hi,
Can some one pleas help me out to order by the month and year.
Actually i have date range from [Jan-2009],[Feb-2009],[Mar-2009]-------[Feb-2010].
I need to order by these results such a way that [Feb-2010],[Jan-2010]-----[Jan-2009].
Thanks
Kp
February 3, 2010 at 6:28 am
Does your column contains values as Feb 2010, Jan 2010 or the column is a datetime datatype?
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
February 3, 2010 at 6:35 am
The Columns are string....I have stored all these into one string variable
February 3, 2010 at 6:54 am
Something like this?
declare @tbl table (datestring varchar(10))
insert into @tbl values ('Jan-2009')
insert into @tbl values ('Feb-2009')
insert into @tbl values ('Mar-2009')
insert into @tbl values ('Feb-2010')
select datestring
from @tbl
order by cast(replace(datestring, '-', ' ') as datetime) desc
_____________________________________________________________________
- Nate
February 3, 2010 at 6:57 am
Thanks Much...That works
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply