Getting exception -Syntax error converting datetime from character string.
Posted By: Arul Posted Date: September 29, 2011
Points:5 Category :Sql Server
Am getting this exception while executing below dynamic query.
select * from MyTable where CONVERT(DATETIME, CONVERT(CHAR(8),JoinDate)) > GETDATE()
JoinDate in MyTable is a numeric field. Which holds values like '20110929'
Also MyTable have some invalid JoinDate like '201109'. So while executing the query am getting this error.
Can any one tell me how to avoid this error with is single query without having any sub queries.
Also I tried below query, still am getting the error.
select * from MyTable where LEN(JoinDate) = 8 AND CONVERT(DATETIME, CONVERT(CHAR(8),JoinDate)) > GETDATE()
You must Sign In To post reply