Pergunta

I'm retrieving data from a SQL Server CE datetime column, I used

CONVERT(NVARCHAR(10), dateHdr, 103)

function to get date from my datetime column but the problem is that it's not ordering column by date properly.

This my query:

SELECT 
   CONVERT(NVARCHAR(10), dateHdr, 103) 
FROM 
   tables0 
GROUP BY 
   CONVERT(NVARCHAR(10), dateHdr, 103) 
ORDER BY 
   CONVERT(NVARCHAR(10), dateHdr, 103) ASC

but it orders columns like this

01/08/2013
01/09/2013
02/08/2013
02/09/2013
Foi útil?

Solução

That is because you are using VARCHAR(10) - it is expected. You might want to use something like below:

SELECT 
CONVERT(DATE,BusDate,103) as Date 
FROM Table
--GROUP BY CONVERT(DATE,BusDate,103) 
ORDER BY Date ASC
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top