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 2008 Forums
 Transact-SQL (2008)
 is error

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2010-11-30 : 04:37:15
how can i write this in query:

SELECT CASE WHEN convert(datetime,(convert(varchar,e.OBPLDT)))
IS ERROR THEN '1900-12-31'
ELSE convert(datetime,(convert(varchar,e.OBPLDT))) END
FROM ..
WHERE...

--------------------------------
suppose i get this value '101010'
SELECT convert(datetime,(convert(varchar,'10101010')))
then i get error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value"

so i do not want that query will fall

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-11-30 : 05:21:39
I think you're looking for the ISDate function.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-30 : 08:26:07
What is the format of the varchar date?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2010-12-01 : 00:49:13
i think isdate is better function
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-12-01 : 02:09:56
quote:
Originally posted by inbs

i think isdate is better function


Make sure to read this
http://beyondrelational.com/blogs/madhivanan/archive/2007/09/24/handle-isdate-with-care.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -