使用 GetDate 时出现 SQL 错误



Msg 241,级别 16,状态 1,第 38 行 从字符串转换日期和/或时间时转换失败。

我尝试过"getdate"和"getdate((但没有运气。

insert into Maintenance([MaintenanceNotes],[MaintenanceDate],[MaintenanceKey])
values ('<?xml version="1.0" encoding="utf-8"?>
<maintenancenote xmlns="http://www.metroalt.com/maintenancenote">
  <title>Wear and Tear on Hydralic units</title>
<note>
  <p>The hydralic units are showing signs of stress</p>
  <p>I recommend the replacement of the units</p>
</note>
  <followup>Schedule replacement for June 2016</followup>
</maintenancenote>', 'GETDATE', 'bus4') 

您需要删除引号,并将其用作实际函数:

    insert into Maintenance([MaintenanceNotes],[MaintenanceDate],[MaintenanceKey])
    values ('<?xml version="1.0" encoding="utf-8"?>
    <maintenancenote xmlns="http://www.metroalt.com/maintenancenote">
      <title>Wear and Tear on Hydralic units</title>
    <note>
      <p>The hydralic units are showing signs of stress</p>
      <p>I recommend the replacement of the units</p>
    </note>
      <followup>Schedule replacement for June 2016</followup>
    </maintenancenote>', GETDATE(), 'bus4') 

为澄清起见,两个单引号之间的任何内容都被视为文本字符串。 GETDATE()是一个函数,因此您需要确保它没有括在引号之间。

最新更新