In with statement:
WITH queryResult AS
(
SELECT
CONVERT(DATETIME, '2017-12-12 ' + PARTIALDATE)
FROM
tableA
WHERE
ISDATE('2017-12-12 ' + PARTIALDATE) = 1
)
....
In this block, I will get exception:
Conversion failed when converting date and/or time from character string.
So I made some changes:
WITH subQueryResult AS
(
SELECT
PARTIALDATE
FROM
tableA
WHERE
ISDATE('2017-12-12 ' + PARTIALDATE) = 1
),
queryResult AS
(
SELECT
CONVERT(DATETIME, '2017-12-12 ' + PARTIALDATE)
FROM
subQueryResult
)
And it works!
But why?
TRY_CAST/TRY_CONVERTcommands - they returnNULL, if something cannot be converted (instead of throwing an error)