在我的Microsoft SQL Server 2005数据库中,我有WorkingDays
列中的数据,如:
<WorkingDays>
<Day>2011-05-05</Day>
<Day>2011-05-06</Day>
</WorkingDays>
如何在T-SQL查询中将它们反序列化为DateTime
格式?
答案 0 :(得分:4)
尝试这样的事情:
DECLARE @TEST TABLE(ID INT IDENTITY, XmlContent XML)
INSERT INTO @TEST(XmlContent) VALUES('<WorkingDays>
<Day>2011-05-05</Day>
<Day>2011-05-06</Day>
</WorkingDays>')
SELECT
ID,
WD.DAYS.value('(.)[1]', 'datetime') AS 'Day'
FROM
@TEST
CROSS APPLY
XmlContent.nodes('/WorkingDays/Day') AS WD(Days)
这给了我一个输出:
ID Day
1 2011-05-05 00:00:00.000
1 2011-05-06 00:00:00.000