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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Ordering

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-01-05 : 09:24:38
I would like to have the dates in order to appear in my dropdown.

Here's the data in the DB and how it appears in the dropdown.

12/25/09
12/18/09
12/11/09
01/01/10

How can I get 01/01/10 to appear on top of the list and the rest in desc order?

This isn't working for me:

SELECT CONVERT(VARCHAR, WKDate, 1) AS [Week]
FROM TSRPTotals
GROUP BY CONVERT(VARCHAR, WKDate, 1)
ORDER BY Week DESC

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-05 : 09:30:57
ORDER BY WKDate DESC

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-01-05 : 09:42:17
Tried that now I'm getting:

Column "TSRPTotals.WKDate" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.


SELECT CONVERT(VARCHAR, WKDate, 1) AS [Week]
FROM TSRPTotals
GROUP BY CONVERT(VARCHAR, WKDate, 1)
ORDER BY WKDate DESC
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-01-05 : 09:45:31
Never mind I got this to work:

SELECT CONVERT(VARCHAR, WKDate, 1) AS [Week]
FROM TSRPTotals
GROUP BY WKDate
ORDER BY WKDate DESC

Thanks for your help!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-06 : 03:17:48
quote:
Originally posted by JJ297

Never mind I got this to work:

SELECT CONVERT(VARCHAR, WKDate, 1) AS [Week]
FROM TSRPTotals
GROUP BY WKDate
ORDER BY WKDate DESC

Thanks for your help!


why are you applying group by? is your attempt to get distinct date values?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-06 : 03:25:40
quote:
Originally posted by visakh16

quote:
Originally posted by JJ297

Never mind I got this to work:

SELECT CONVERT(VARCHAR, WKDate, 1) AS [Week]
FROM TSRPTotals
GROUP BY WKDate
ORDER BY WKDate DESC

Thanks for your help!


why are you applying group by? is your attempt to get distinct date values?


Yes. I think so

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-01-06 : 13:30:40
Sorry for the late reply...yes it is to get the distinct values. Thanks!
Go to Top of Page
   

- Advertisement -