Thursday, March 29, 2012

Does SQL Server support XML Functions

Hi,
Do any versions of SQL Server support the following functions, as
they appear in the Oracle Database:-

1) XMLElement
2) XMLAttributes
3) XMLForest

Thanks in Advance for your reply
Bye
Amardeep VermaAmardeep Verma (addverma@.netscape.net) writes:
> Do any versions of SQL Server support the following functions, as
> they appear in the Oracle Database:-
> 1) XMLElement
> 2) XMLAttributes
> 3) XMLForest
> Thanks in Advance for your reply

Since I don't know Oracle, I don't know what these functions do. It is
not likely that SQL Server supports these functions directly, but it
may support the same functionality. You would need to explain what these
functions do to get answer.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Hi,
Thanks Erland for your Response. These Functions take simple
SELECT statement and return the result in a XML format. With each
Column name as a tag and the value in that column as the data.
For Example the Employee Table of NorthWind Database has 3
columns:-
1) EmpNo
2) EmpLastName
3) EmpFirstName
Then using the below mentioned functions we can get the output
<EMP>
<EMPNo>1</EMPNo>
<EMPFirstName>ABC</EMPFirstName>
<EMPLastName>XYZ</EMPLastName>
</EMP
Hope this helps
Amardeep Verma

Erland Sommarskog <esquel@.sommarskog.se> wrote in message news:<Xns9536EC50E4C4FYazorman@.127.0.0.1>...
> Since I don't know Oracle, I don't know what these functions do. It is
> not likely that SQL Server supports these functions directly, but it
> may support the same functionality. You would need to explain what these
> functions do to get answer.|||Amardeep Verma (addverma@.netscape.net) writes:
> Thanks Erland for your Response. These Functions take simple
> SELECT statement and return the result in a XML format. With each
> Column name as a tag and the value in that column as the data.
> For Example the Employee Table of NorthWind Database has 3
> columns:-
> 1) EmpNo
> 2) EmpLastName
> 3) EmpFirstName
> Then using the below mentioned functions we can get the output
><EMP>
> <EMPNo>1</EMPNo>
> <EMPFirstName>ABC</EMPFirstName>
> <EMPLastName>XYZ</EMPLastName>
></EMP
It looks like you should study the FOR XML clause in the SELECT statement.
It gives you several possibilities. Rather than typing examples here,
I refer you to Books Online myself, since I am no XML wizard myself.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||SQL sever has a few ways to generate xml. An example below that
conforms to your spec(ie columns as elements) can be viewed in QA

select * from employees
where employeeid=1 for xml auto, elements

NOTE: it is best run when the query is set to 'Results in text' and
also
'DBCC TRACEON(257)' has been run first

No comments:

Post a Comment