1
I have the following select:
SELECT a.nome, a.cidade, a.telefone, a.dt_criado
FROM cadastro AS a
GROUP BY a.nome, a.cidade, a.telefone, a.dt_criado
HAVING COUNT(*) > 0
ORDER BY a.dt_criado
DESC
a. dt_created is a varchar, but does not order correctly.
Select result:
02/05/2018 - 15:38:21 02/05/2018 - 15:39:48 02/05/2018 - 15:40:05 02/05/2018 - 15:44:19 02/05/2018 - 17:41:42 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 14:11:29 03/05/2018 - 14:12:04 03/05/2018 - 14:13:06 03/05/2018 - 14:48:59 20/04/2018 - 09:35:59 20/04/2018 - 12:38:13 20/04/2018 - 16:49:15 20/04/2018 - 16:49:31 20/04/2018 - 16:55:23 20/04/2018 - 16:55:23 20/04/2018 - 16:55:23 -
Could you post a small sample of the content? And how it looks after order by?
– Clayton Tosatti
dt_created 02/05/2018 - 15:38:21 02/05/2018 - 15:39:48 02/05/2018 - 15:40:05 02/05/2018 - 15:44:19 02/05/2018 - 17:41:42 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 08:53:06 03/05/2018 - 14:11:29 03/05/2018 - 14:12:04 03/05/2018 - 14:13:06 03/05/2018 - 14:48:59 20/04/2018 - 09:35:59 20/04/2018 - 12:38:13 20/04/2018 - 16:49:15 20/04/2018 - 16:49:31 20/04/2018 - 16:55:23 20/04/2018 -2018 - 16:55:23 04/20/2018 - 16:55:23
– user111394
exchange for
order by Convert(datetime,a.dt_criado,103) desc
– Marconi
Conversion failed when Converting date and/or time from Character string.
– user111394
I made a change, it’s datetime instead of date
– Marconi
now gave: The Conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
– user111394
There is some date your incomplete. I will post a Fiddle for you to see!
– Marconi
Take a look here: http://sqlfiddle.com/#! 18/ca821/1
– Marconi
I had a similar problem in Oracle by a legacy table with a "date" field that is a string , I did the following a Function converts to string to date , but in a protected block treating conversion error and returning null in this case, is not the best solution but it was the possible.
– Motta
apparently by sqlfiddle everything normal....
– user111394
maybe if ordering just by day/month/year would help even if it doesn’t take the time...has how to make a substring will be?
– user111394