使用GetDate时发生Sql错误

使用GetDate时发生Sql错误,sql,sql-server,tsql,Sql,Sql Server,Tsql,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.metroal

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') 
插入到维护中([MaintenanceNotes]、[MaintenanceDate]、[MaintenanceKey])
价值('
液压装置的磨损
液压装置显示出压力的迹象

我建议更换这些装置

2016年6月的时间表替换 '、'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') 
插入到维护中([MaintenanceNotes]、[MaintenanceDate]、[MaintenanceKey])
价值('
液压装置的磨损
液压装置显示出压力的迹象

我建议更换这些装置

2016年6月的时间表替换 ,GETDATE(),'bus4')

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

我想给您一点建议,因为这是您的第二个问题,在相同的查询中,您只需发布您收到的错误:在您在这里写问题之前,请尝试通过搜索您收到的错误消息来找到答案。看起来您是一个我是sql的初学者。因为这是一个非常丰富的信息资源,您可以立即找到如何使用
getdate()