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
 sort by day of week

Author  Topic 

egghi
Starting Member

17 Posts

Posted - 2006-11-09 : 11:33:08
Hi,

I have a query that works but I need to sort the data by day of week..

Right now, results look like this:

Friday 2
Saturday 1
Thursday 3
Wednesday 1

And I need it to look like
Wednesday 1
Thursday 3
Friday 2
Saturday 1

Here is the current query:

SELECT Datename(dw,[Date]) AS [Day],COUNT(*)
FROM Dates, TimeOff
WHERE [Date] BETWEEN OffStartDate AND OffEndDate AND OffType = 'Sick Day'
GROUP BY Datename(dw,[Date])
ORDER BY ....

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-09 : 11:37:41
[code]Order BY Datename(weekday,[Date])[/code]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

egghi
Starting Member

17 Posts

Posted - 2006-11-09 : 11:44:48
Hello Harsh,

Thank you for your quick response! I added your order by statement but it did not work... The result still sorts in alphabetical order instead of day of week...
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-11-09 : 12:04:18
use the day of week datepart ... not the datename

Jay White
Go to Top of Page
   

- Advertisement -