I have a large table with 1 million + records. Unfortunately, the person who created the table decided to put the dates in the field varchar(50).
I need to do a simple date comparison -
datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
But it does not work on convert():
Conversion failed when converting datetime from character string.
Apparently, there is something in this field that he does not like, and since there are so many entries in it, I canβt say just by looking at it. How can I correctly deactivate the entire date field so that it does not interrupt on convert()? Here is what I have now:
select count(*)
from MyTable
where
isdate(lastUpdate) > 0
and datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
@SQLMenace
In this case, performance does not concern me. This will be a one-time request. Changing the table in the date and time field is not an option.
@Jon Limjap
I tried to add a third argument, and that doesn't make any difference.
@SQLMenace
, , , , ; ISO YYYYMMDD; ISO 8601 yyyy-mm-dd Thh: mm: ss: mmm ( )
isdate() ?
100%. 30 .
@SQLMenace
select isdate('20080131')
select isdate('01312008')
@Brian Schkerke
CASE ISDATE CONVERT().
! .