0

I have a scenario whereby the hosting provider will only provide a backup SQL script of a MSSQL database. This results in DateTime values being scripted as '05/12/2011 17:04:00'.

Hence the error,

"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."

Does anyone know a way whereby I could find all DateTime values and wrap them with Cast(... As DateTime)?

Sean Dooley
  • 615
  • 2
  • 11
  • 27

1 Answers1

0

try this it working

select cast('05/12/2011 17:04:00' as DateTime)
Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
  • Only if the value of month and date values goes out of range then it will show that error. Since Sql Server will accept date in this format `mm/dd/yyyy` rather than this it will show that error – Kishore Kumar Mar 19 '12 at 17:00
  • See here i have given this value `select cast('14/20/2011 17:04:00' as DateTime)` and the error shown is `The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.` – Kishore Kumar Mar 19 '12 at 17:00
  • There are many INSERT statements where is this happening. Is there a way to mass update the INSERT statements? Or am I approaching this from the wrong direction? – Sean Dooley Mar 19 '12 at 17:02