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 |
fogofogo
Starting Member
11 Posts |
Posted - 2008-10-30 : 05:45:35
|
Hello, I'm trying to change a column datatype in a ms sql 2000 database, that contains 700k records. Its currently set as a varchar, and I need to change it to a datetime format. The dates in the column are set as dd/mm/yyyy ( 20/02/2007).When I try to change it I get this error...ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. So obviously there is dodgy date in one of the rows. Does anyone know any sql function that I can use to run and select the records with the date errors?Thanks Matt |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-30 : 06:15:40
|
you may use thisselect * from yourtable where isdate(datefield)=0or (isdate(datefield)=1 and len(datefield)<8) |
 |
|
fogofogo
Starting Member
11 Posts |
Posted - 2008-10-30 : 06:56:26
|
Thank you.Here is what I have discoved...The dates that are ok are in this format dd/mm/yyyy, but the dates with the errors are mm/dd/yyyySo, 12/10/2008 is fine, where 13/10/2008 is not.Thousands of records are in the wrong format - is there anyway I can change them using sql?Thanks again |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-30 : 07:10:03
|
Assuming you don't have mixed Dates in your table.Assuming they're always dd/mm/yyyy.set language germanselect convert(datetime,'13/12/2008')and maybe then...set language englishWebfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-30 : 08:20:59
|
Always use proper datetime datatype to store datesset dateformat dmy--do processset dateformat mdyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|