In my Microsoft SQL Server 2005 database I have data in column WorkingDays
like :
<WorkingDays>
<Day>2011-05-05</Day>
<Day>2011-05-06</Day>
</WorkingDays>
How to deserialize them within T-SQL query to DateTime
format?
Try something like this:
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)
This gives me an output of:
ID Day
1 2011-05-05 00:00:00.000
1 2011-05-06 00:00:00.000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With