Conversion failed when converting date and/or time from character string in SQL SERVER 2008

后端 未结 3 1592
长发绾君心
长发绾君心 2021-01-13 07:34

I have below SQL.

 UPDATE  student_queues
 SET  Deleted=0,  
      last_accessed_by=\'raja\', 
      last_accessed_on=CONVERT(VARCHAR(24),\'23-07-2014 09:37:         


        
3条回答
  •  甜味超标
    2021-01-13 08:21

    Seems like last_accessed_on, is a date time, and you are converting '23-07-2014 09:37:00' to a varchar. This would not work, and give you conversion errors. Try

    last_accessed_on= convert(datetime,'23-07-2014 09:37:00', 103)  
    

    I think you can avoid the cast though, and update with '23-07-2014 09:37:00'. It should work given that the format is correct.

    Your query is not going to work because in last_accessed_on (which is DateTime2 type), you are trying to pass a Varchar value.

    You query would be

    UPDATE  student_queues SET  Deleted=0 ,  last_accessed_by='raja', last_accessed_on=convert(datetime,'23-07-2014 09:37:00', 103)  
     WHERE std_id IN ('2144-384-11564') AND reject_details='REJECT'
    

提交回复
热议问题