From: Plamen Ratchev on
That means that some values are invalid dates. Try this:

SELECT CASE WHEN ISDATE(CAST(LDate AS CHAR(8))) = 1
THEN CAST(CAST(LDate AS CHAR(8)) AS DATETIME)
END
FROM dbo.Schedules;

--
Plamen Ratchev
http://www.SQLStudio.com
From: hayko98 on
On Oct 6, 4:36 pm, Plamen Ratchev <Pla...(a)SQLStudio.com> wrote:
> That means that some values are invalid dates. Try this:
>
> SELECT CASE WHEN ISDATE(CAST(LDate  AS CHAR(8))) = 1
>              THEN CAST(CAST(LDate  AS CHAR(8)) AS DATETIME)
>         END
> FROM dbo.Schedules;
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

Thank You very much.It worked.
From: Madhivanan on
On Oct 7, 4:36 am, Plamen Ratchev <Pla...(a)SQLStudio.com> wrote:
> That means that some values are invalid dates. Try this:
>
> SELECT CASE WHEN ISDATE(CAST(LDate  AS CHAR(8))) = 1
>              THEN CAST(CAST(LDate  AS CHAR(8)) AS DATETIME)
>         END
> FROM dbo.Schedules;
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

Note that isdate() is not reliable
You need to check the length too

SELECT CASE WHEN ISDATE(CAST(LDate AS CHAR(8))) = 1 and LEN(LDate)=8
THEN CAST(CAST(LDate AS CHAR(8)) AS DATETIME)
END
FROM dbo.Schedules;