Modifying date field in XML document stored in SQL Server table -
i have xml document stored in sql server table xml column has inaccurate times in date fields
i 'd update date , time (saledatetime, linestarttime, lineendtime) values in document 15 seconds so, instance, 2012-02-01t00:07:50 becomes 2012-02-01t00:08:05 (long story why needs way; it's out of hands). there can 1 many transactions , each transaction can have 1 or more line entries.
i have tried openxml, modify method, etc dateadd , can't right. @ wits end. appreciated. in advance!!
sample below
create table xmltable (doc xml); insert xmltable (doc) values ( '<?xml version="1.0" encoding="utf-8"?> <root> <transaction> <saleid>1</saleid> <sale> <saledatetime>2012-02-01t00:07:00</saledatetime> <lineitem> <line>1</line> <linestarttime>2012-02-01t00:07:00</linestarttime> <lineendtime>2012-02-01t00:07:00</lineendtime> <amount>13.50</amount> </lineitem> </sale> </transaction> <transaction> <saleid>2</saleid> <sale> <saledatetime>2012-02-01t00:11:00</saledatetime> <lineitem> <line>1</line> <linestarttime>2012-02-01t00:11:00</linestarttime> <lineendtime>2012-02-01t00:11:00</lineendtime> <amount>13.50</amount> </lineitem> <lineitem> <line>2</line> <linestarttime>2012-02-01t00:11:00</linestarttime> <lineendtime>2012-02-01t00:11:00</lineendtime> <amount>5.22</amount> </lineitem> </sale> </transaction> </root>') select * xmltable
you can use modify
method. example replace first occurance of saledatetime
:
declare @now datetime = getdate() update xmltable set doc.modify('replace value of (/root/transaction/sale/saledatetime/text())[1] sql:variable("@now")')
Comments
Post a Comment