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

后端 未结 7 2435
梦毁少年i
梦毁少年i 2020-11-27 06:33

I have the following piece of inline SQL that I run from a C# windows service:

UPDATE table_name SET 
    status_cd = \'2\', 
    sdate = CAST(\'03/28/2011 1         


        
7条回答
  •  庸人自扰
    2020-11-27 07:31

    Ambiguous date formats are interpreted according to the language of the login. This works

    set dateformat mdy
    
    select CAST('03/28/2011 18:03:40' AS DATETIME)
    

    This doesn't

    set dateformat dmy
    
    select CAST('03/28/2011 18:03:40' AS DATETIME)
    

    If you use parameterised queries with the correct datatype you avoid these issues. You can also use the unambiguous "unseparated" format yyyyMMdd hh:mm:ss

提交回复
热议问题