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.
Author |
Topic |
cardgunner
326 Posts |
Posted - 2011-07-15 : 09:18:12
|
I'm trying to cast a set a value as datetime but I get the error that they are out-of-range. Is there a way to write a statement that if the field is out-of-range then 'ERROR' if not then the date.This will help me identify which ones are in error so I could correct them.CardGunner |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-07-15 : 09:44:01
|
Try ISDATE() function.If SQL Server in any way can interpret the data as a date, the function will return 1, otherwise 0.SELECT ISDATE(Col1) N 56°04'39.26"E 12°55'05.63" |
 |
|
cardgunner
326 Posts |
Posted - 2011-07-15 : 10:23:28
|
That works thank you.CardGunner |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-07-19 : 05:56:00
|
If the values are in particular format, you may also need to use len function tooWHERE LEN(col1)=format_length AND ISDATE(Col1)MadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-07-19 : 08:22:58
|
If you know which format ALL rows are, use CONVERT(DATETIME, Col1, 101) -- mm/dd/yyyy for example. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|