Hi
I have the following code but it is not ordering the dates correctly.
SELECT TOP (100) PERCENT CONVERT(VarChar(10), DateRequired, 103) AS [Date Required], SUM(TotalVolume) AS M3
FROM dbo.[148-vwOrderHeadCP]
WHERE (DateRequired >= CAST(GETDATE() AS DATE)) AND (DateRequired <= DATEADD(day, 7, CAST(GETDATE() AS DATE))) AND (OrderStatus <> 1) AND (OrderStatus <> 0) AND
(OrderStatus <> 11)
GROUP BY CONVERT(VarChar(10), DateRequired, 103)
ORDER BY [Date Required] DESC
It groups the dates like this
29/05/2015
28/05/2015
27/05/2015
03/06/2015
02/06/2015
01/06/2015
Where it should be
27/05/2015
28/05/2015
29/05/2015
01/06/2015
02/06/2015
03/06/2015
I tried changing the last line to
ORDER BY CONVERT(VarChar(10), DateRequired, 103) DESC
But I got the same result, I have tried many variations but cannot get the result I need. Any ideas how I can change the code so it order's correctly
Thanks
I have the following code but it is not ordering the dates correctly.
SELECT TOP (100) PERCENT CONVERT(VarChar(10), DateRequired, 103) AS [Date Required], SUM(TotalVolume) AS M3
FROM dbo.[148-vwOrderHeadCP]
WHERE (DateRequired >= CAST(GETDATE() AS DATE)) AND (DateRequired <= DATEADD(day, 7, CAST(GETDATE() AS DATE))) AND (OrderStatus <> 1) AND (OrderStatus <> 0) AND
(OrderStatus <> 11)
GROUP BY CONVERT(VarChar(10), DateRequired, 103)
ORDER BY [Date Required] DESC
It groups the dates like this
29/05/2015
28/05/2015
27/05/2015
03/06/2015
02/06/2015
01/06/2015
Where it should be
27/05/2015
28/05/2015
29/05/2015
01/06/2015
02/06/2015
03/06/2015
I tried changing the last line to
ORDER BY CONVERT(VarChar(10), DateRequired, 103) DESC
But I got the same result, I have tried many variations but cannot get the result I need. Any ideas how I can change the code so it order's correctly
Thanks