Xml element insertion in XML DATA


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Adding element INTO the XML DATA
  2. INSERT
  3. Expression1 (
  4. {AS FIRST | AS LAST} INTO | after | BEFORE
  5. Expression2
  6. )
  7.  
  8. SET @xmlDoc.modify('
  9. insert element UpdateDatetime {"2010-10-28T13:49:27.330"} before or after
  10. (/t/AuditID)[1]
  11. ')
  12. SET @xmlDoc.modify('
  13. insert <UpdateDatetime>2010-10-28T13:49:27.330</UpdateDatetime>
  14. as last or as first or
  15. into(/t)[1]')
  16. IF (@xmlDoc.exist('/t/UpdateDatetime')=0)
  17. BEGIN
  18. SET @xmlDoc.modify('
  19. insert <UpdateDatetime>2010-10-28T13:49:27.330</UpdateDatetime>
  20. as last
  21. into(/t)[1]')
  22. END
  23.  
  24. *Adding element WITH dynamic DATA FROM the sp parameters WITH condition.
  25.  
  26. IF (@xmlDoc.exist('/t/UpdateDatetime')=0)
  27. BEGIN
  28. SET @xmlDoc.modify('
  29. insert element UpdateDatetime {sql:variable("@dtmCurrentDate")}
  30. as last
  31. into(/t)[1]')
  32. END

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.