Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
My 'sort by week' has flaw
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00818062
Message ID:
00818064
Views:
18
Hi Michael,

The following expression will group/sort by year and week (yyyyww).
GROUP BY DATEPART(yyyy, [time]) * 100 + DATEPART(dw, [time])
>I'm sorting and grouping by week using this syntax:
>
>GROUP BY CONVERT(varchar(10), [time] - DATEPART(dw, [time]), 101)
>
>But I'm finding data from the previous year at the end of my result set, instead of at the beginning.
>
>How can I include the year to make it sort properly...
>
>TIA
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform