lundi 10 août 2015

Whats wrong with the following date sort query

I am using the following query to sort the output. It works in some cases but not all. Any suggestion why? any alternate please.

Select 
    'playing' As activity,
    max(ad.xDate) As xDate,
    Isnull(sum(t.TimePerDay), 0) As TimePerDay 
From    
    AllDates As ad With (Nolock) 
Left Join 
    @test As t On ad.xDate = t.date
Group By
    datepart(wk, ad.xDate)
Order By
    YEAR(datepart(wk, ad.xDate)) DESC, MONTH(datepart(wk, ad.xDate)) DESC, DAY(datepart(wk, ad.xDate))

Aucun commentaire:

Enregistrer un commentaire