sql - Avoid errors when attempting to convert to datetime -
is there way in sql ignore records conversion failed. setting default value work.
> select convert(datetime, foo_str) > foo_tbl ------------------------ aug 23 2013 00:00:00.000 aug 17 2013 00:00:00.000 may 06 2015 00:00:00.000 aug 13 2013 00:00:00.000 aug 09 2013 00:00:00.000 sep 05 2007 00:00:00.000 may 06 2015 00:00:00.000 may 06 2015 00:00:00.000 feb 24 2009 00:00:00.000 may 06 2015 00:00:00.000 mar 29 2013 00:00:00.000 may 06 2015 00:00:00.000 jul 24 2010 00:00:00.000 may 06 2015 00:00:00.000 may 06 2015 00:00:00.000 may 03 2015 00:00:00.000
msg 249, level 16, state 1 , line 1 syntax error during explicit conversion of varchar value '10101' datetime field.
can error avoided select statements comes completion?
something below code should work on sybase
select convert(datetime, foo_str) foo_tbl foo_str '[a-z][a-z][a-z] [0-1][0-9] [0-2][0-9][0-9][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9].[0-9][0-9][0-9]'
if 00:00:00.000
constant can simpler
select convert(datetime, foo_str) foo_tbl foo_str '[a-z][a-z][a-z] [0-1][0-9] [0-2][0-9][0-9][0-9] 00:00:00.000'
or
select convert(datetime, foo_str) foo_tbl foo_str '[a-z][a-z][a-z] [0-1][0-9] [0-2][0-9][0-9][0-9]%'
Comments
Post a Comment