I'm running a query in a view, but one of its fields is text, in this field the user can enter a date (xx / xx / xxxx) as well as any other type information. I would like to know how I can return only the records I can convert to date or how can I handle the error below, what happens when I try to convert the field to the type I need?
Error: Conversion failed when converting date and / or time from character string.
Query I'm doing:
SELECT
V.CAMPO1,
V.CAMPO1,
V.CAMPO1,
V.CAMPO_CHAR_DATA,
CASE WHEN RTRIM(V.CAMPO_CHAR_DATA) <> '' THEN
CONVERT(DATETIME, RTRIM(V.CAMPO_CHAR_DATA, ),103)
ELSE '2017-01-01 00:00:00'
END AS CAMPO_CHAR_DATA
FROM VIEW_TESTE V