Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trouble with ORDER BY
Message
 
To
10/04/2003 18:38:03
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00776296
Message ID:
00776389
Views:
19
Excellent point - thanks! I need to display the date, so I may need to keep the date text field unless I can concatenate from the new field.

>Michael,
>
>I think this should work for you, it does a direct conversion to varchar:
>
>SELECT Convert(varchar(10), time, 101) AS DayField,
>COUNT(CondoDir) AS Hits FROM wwRequestLog
>WHERE UPPER(CondoDir) LIKE 'FRANKLIN'
>AND DATEDIFF(day, time, getdate()) < 14
>GROUP BY time
>ORDER BY time
>
>If you use ORDER BY on a varchar field converted from datetime, the rows may not end up sorted correctly, for example "01/01/1998" will be returned before "01/02/1997".
>
>Roman
>
>
>>>You should be able to add GROUP BY and ORDER BY DayField into you SELECT statement.
>>>
>>>Stephen
>>>
>>It doesn't allow me to use DayField, but it does work if I use:
>>ORDER BY (cast(datepart(mm,time) as varchar)+'/'+datename(dd,time)+'/'+datename(yyyy,time))
>>
>>After the GROUP BY
>>
>>I thought I tried this before. I must have dropped a paren.
>>
>>Thanks!
>>
>>>
>>>>>SELECT (cast(datepart(mm,time) as varchar)+'/'+datename(dd,time)+'/'+datename(yyyy,time)) AS DayField,
>>>>>COUNT(CondoDir) AS Hits FROM wwRequestLog
>>>>>WHERE UPPER(CondoDir) LIKE 'FRANKLIN'
>>>>>AND DATEDIFF(day, time, getdate()) < 14
>>>>>GROUP BY (cast(datepart(mm,time) as varchar)+'/'+datename(dd,time)+'/'+datename(yyyy,time))
>>>>>
>>>>>
>>>>>TIA
Kogo Michael Hogan

"Pinky, are you pondering what I'm pondering?"
I think so Brain, but "Snowball for Windows"?

Ideate Web Site
Previous
Reply
Map
View

Click here to load this message in the networking platform