Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Avoid invalid dates

Author  Topic 

dani2
Starting Member

32 Posts

Posted - 2008-10-08 : 02:30:34
For some reasons a table string column contains values of null and '1-1-0001'. When converting those to datetime arithmetic overflow error is raised. How can I avoid such values in the select query?


Thank you.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-08 : 03:06:44
You can for example use ISDATE() in your WHERE-Clause.
ISDATE() returns 0 when the given value is not a date.
Examples:
select isdate('1-1-0001') --> returns 0
select isdate(null) --> returns 0
select isdate('20081008') --> returns 1

add to your SELECT something like this:
Where ...
and isdate(yourcolumn) = 1


Greetings
Webfred


Planning replaces chance by mistake
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-08 : 03:09:24
ISDATE() is not fully reliable. So you might need to add extra condition checks also

http://sqlserver-qa.net/blogs/t-sql/archive/2007/09/24/2177.aspx

Go to Top of Page
   

- Advertisement -