Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 adding attribute in XML using xQuery

Author  Topic 

enableDeepak
Starting Member

2 Posts

Posted - 2007-12-07 : 05:37:17
Suppose I have a simple SQL block:

--- code starts---
DECLARE @Content xml
SET @Content='<Book><chapter></book>'
--- code ends-----

Questions:
Q1. How can I add an attrbite "@ID=1" to the chapter element using xQuery modify method?
something like "SET @Content.modify(insert...."

Q2. Once one is done, how can I update the value of @ID?

ayamas
Aged Yak Warrior

552 Posts

Posted - 2007-12-07 : 07:33:47
Why you want to add an attribute?You can have a column as ID and in the other column say "Books" which will be of xml datatype put the xml values..!
Go to Top of Page

enableDeepak
Starting Member

2 Posts

Posted - 2007-12-07 : 07:37:23
On front end I have complex existing business logic as a result of which I need this kind of functionality. This books sample is just an example. I am actually interested in knowing that how can I append attributes (not the ELEMENT.. ONLY ATTRIBUTES) to an existing XML content residing in a SQL XML data type variable!
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2007-12-07 : 07:49:03
Maybe this will be of some help for you

http://msdn2.microsoft.com/en-us/library/ms345110.aspx
Go to Top of Page
   

- Advertisement -