I have a database with a field like this (Dont know why it's varchar):
i'm trying to convert it to DATE as DDMMYYYY.
I could do this with:
convert(varchar(10), cast(The_ugly_field as date),103)
Then my date is:
1) Why I can't convert it directly to date? if I use:
select convert(date,The_ugly_field,103) from Ugly_Table
1900-01-01 and it doesnt respect the 103. any number there returns the same format YYYY-MM-DD.
2)Now the real question. when I run
select convert(varchar(10), cast(The_ugly_field as date),103) From Ugly_Table order by The_ugly_field
after some time it returns this error:
Msg 241, Level 16, State 1, Line 29 Conversion failed when converting date and/or time from character string.
but the funny part is, it doesnt looks like the errors appears in the same row. If I run this code like 4 times, every time it returns the error, it says a different row. I mean, I execute it, then in the "results" tab I can see that it returned
1.234.555 rows. If I run it again, after the error I return to the "result" table and now the query ran until
and please. how the hell can I convert this
20140101 in a elegant way to
convert(date,E1_EMISSAO,103) doesn't seems to respect the
103 and it returns
2017-02-24 and not
tons of questions and answers but it's all about a simple convert().