|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 29, 2012 1:39 PM
Points: 6,
Visits: 49
|
|
Hi, The last example in the article is not working, gives an error: XQuery: SQL type 'xml' is not supported in XQuery.
THe example is: DECLARE @x XML SELECT @x = ' <Employees> <Employee Team="SQL Server">Jacob</Employee> </Employees>'
DECLARE @emp XML SELECT @emp = '<Employee Team="SQL Server">Steve</Employee>'
SET @x.modify(' insert sql:variable("@emp") into (Employees)[1] ')
SELECT @x /* <Employees> <Employee Team="SQL Server">Jacob</Employee> <Employee Team="SQL Server">Steve</Employee> </Employees> */
PS IRRELEVANT. Works in 2008 and needs dynamic sql in 2005
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
The last example clearly mentions that it will work only on SQL Server 2008 and above. Are you running the example on SQL Server 2005?
.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 29, 2012 1:39 PM
Points: 6,
Visits: 49
|
|
Yes, I'm sorry. Just got it and didn't had time to reply. Thanks for the fast reply. I'll try to update my first comment or remove it
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, February 08, 2013 10:42 PM
Points: 27,
Visits: 45
|
|
I have one XML
<Root> <Student>Jhon </Student> <Student> Luka </Student> <Post>1</Post> <Post>2</Post> </Root>
Is it possible to add root node called Students for Student section and Posts for Post, as given below?
<Root> <Students> <Student>Jhon </Student> <Student> Luka </Student> </Students> <Posts> <Post>1</Post> <Post>2</Post> </Posts> </Root>'
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
This can be achieved by a FLWOR operation.
DECLARE @x XML = ' <Root> <Student>Jhon </Student> <Student> Luka </Student> <Post>1</Post> <Post>2</Post> </Root>'
SELECT @x.query (' for $i in (Root) let $s := $i/Student let $p := $i/Post return <Root> <Students> {$s} </Students> <Posts>{$p}</Posts> </Root> ')
/* Produces: <Root> <Students> <Student>Jhon </Student> <Student> Luka </Student> </Students> <Posts> <Post>1</Post> <Post>2</Post> </Posts> </Root> */
This is one of those scenarios where the FLWOR operation is quite handy. I just added this example to the XQuery Labs
.
|
|
|
|