From: Plamen Ratchev on 6 Oct 2009 19:36 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 8 Oct 2009 14:17 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 20 Oct 2009 09:08
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; |