Question : SQL query to extract date from the xml TEXT

Hello Experts,

I have XML data stored in the column of TEXT datatype, I am trying to update the TimeStamp column with the date when this XML data has been requested ...

I want to stream through the XML and get the date from the following node

RequestDate="2009-11-13T22:35:55"

Once I get the date then update TimeStamp column with this date.

Order
====
orderid PrintRequest TimeStamp
------------------------------------------
1           XML data      NULL
2           XML data      NULL
3           XML data      NULL

I want to update the  timestamp with the date in the XML

I hope someone can advise how can I go about doing this?

Thanks in advance

Regards
S
Code Snippet:
1:
G0ftR5publ0cUserAgent

Answer : SQL query to extract date from the xml TEXT

Hi Newbie27

Your xml data is sotred in text column, so we cannot directly use the xml methods. so i conver the text datatype to xml and store the result in table variable and then i update the date in Order table

Try this code

DECLARE @tmpOrder TABLE(xmld  XML, t_orderid NUMERIC(10))
INSERT INTO @tmpOrder
SELECT CONVERT(XML,xml_data),OrderId from Order

UPDATE      Order
SET      TimeStamp =  xmld.value('(/Start/PurchaseOrder/@RequestDate)[1]', 'DATETIME')
FROM      @tmpOrder
WHERE    orderid = t_orderid

Random Solutions  
 
programming4us programming4us