| Author |
Topic |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-18 : 13:57:58
|
| How can I get these dates to appear the highest to the lowest.01/29/1002/26/1010/30/0911/27/0912/25/09I used this procedure to get the above data but it's not coming out in the oder that I want. I would like 02/26/10 first then 01/29/10 etc... Thanks.SELECT convert(varchar,DowrDate,1) as DowrDateFROM TSRPTotalsgroup by DowrDateorder by DowrDate |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-18 : 14:00:21
|
| Assuming your "Dates" are stored as a Date data type:ORDER BY DateColumn DESC |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-18 : 14:22:21
|
| I added this:SELECT convert(varchar,DowrDate,1) as DowrDateFROM TSRPTotalsgroup by DowrDateorder by DowrDate DESCand got this...12/25/0911/27/0910/30/0902/26/1001/29/10Dowrdate is datetime in the database. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-02-18 : 14:32:12
|
This works for me...is this your entire query?declare @t table (col1 datetime)insert @tselect '20100226'union all select '20091225'union all select '20091225'union all select '20091030'union all select '20091127'union all select '20100129'select convert(varchar,col1,1) from @tgroup by col1order by col1 desc |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-18 : 14:57:56
|
| Yes here the entire stored procedure:ALTER procedure [dbo].[GetMonth]ASSELECT convert(varchar,DowrDate,1) as DowrDateFROM TSRPTotalsgroup by DowrDateorder by DowrDate DESC |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-18 : 14:59:58
|
| It does work but I wanted the 2010 dates listed first so 02/26/2010 should be first. I hope that makes sense. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-02-18 : 15:07:15
|
Yes..it does order properly ...this is the output..Did you try it?Dates------------------------------02/26/1001/29/1012/25/0911/27/0910/30/09 |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-18 : 15:13:22
|
| My mistake yes it works. Sorry about that I was looking at the other query without desc added to it. Thanks! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 01:24:45
|
quote: Originally posted by JJ297 Yes here the entire stored procedure:ALTER procedure [dbo].[GetMonth]ASSELECT convert(varchar,DowrDate,1) as DowrDateFROM TSRPTotalsgroup by DowrDateorder by DowrDate DESC
As per your code dates will be ordered by varcharsThats why you should do formation at front end application if you use itMadhivananFailing to plan is Planning to fail |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-02-19 : 08:50:51
|
| Thanks that was my problem. Once I moved the varchar I got the order I was looking for. |
 |
|
|
|