sql - Update Query (String --> Date) -
this question has answer here:
i'm trying update field (type of date) string field.
the string field example : 20/10/2015
i new in sql. tried query:
update [dbo].[employeewithcompcar] set [emer_attachenddate] = cast([emer_info1] date)
i message:
conversion failed when converting date and/or time character string.
can me fix it?
thank's!
you need use convert()
format. try this:
update [dbo].[employeewithcompcar] set [emer_attachenddate] = convert(date, [emer_info1], 103);
the formats available in documentation.
note: in sql server 2012+, use try_convert()
instead of convert()
. way, if string in wrong format, result null
instead of error.
Comments
Post a Comment