SQL、OPENXML 和 DateTime 对话
我继承了大量存储过程,它们将 XML 块作为唯一参数,然后作者破解它(使用 OPENXML),然后更新一行。
我在更新具有日期时间列的表时遇到问题,以下是当前失败的数据片段:
declare @stuff nvarchar (max);
set @stuff =
'<Booking xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UpdatedDateTime>2009-08-14T15:32:09.7240556+01:00</UpdatedDateTime>
</Booking>';
declare @iDoc int;
exec sp_xml_preparedocument @idoc OUTPUT, @stuff;
SELECT UpdatedDateTime
FROM
OPENXML(@idoc, '/*')
WITH
(
UpdatedDateTime datetime 'UpdatedDateTime'
)
运行会导致以下错误:
消息 241,级别 16,状态 1,第 12 行
转换时转换失败 来自字符串的日期时间。
如何将 XML 片段中的日期时间转换为基于 SQL 的日期时间?
谢谢
I've inherited a mass of stored procedures that take as their only parameter a block of XML, the author then cracks it (using OPENXML) and then updates the a row.
I've come across a problem while updating a table that has datetime columns, the following is a snippet of data that currently fails:
declare @stuff nvarchar (max);
set @stuff =
'<Booking xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UpdatedDateTime>2009-08-14T15:32:09.7240556+01:00</UpdatedDateTime>
</Booking>';
declare @iDoc int;
exec sp_xml_preparedocument @idoc OUTPUT, @stuff;
SELECT UpdatedDateTime
FROM
OPENXML(@idoc, '/*')
WITH
(
UpdatedDateTime datetime 'UpdatedDateTime'
)
Running that causes the following error:
Msg 241, Level 16, State 1, Line 12
Conversion failed when converting
datetime from character string.
How do I go about converting the datetime from the XML fragment into a SQL based date time?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
结果集:
try:
results set: