Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Is FOR XML RAW, ELEMENTS = FOR XML PATH, ELEMENTS? Expand / Collapse
Author
Message
Posted Friday, May 23, 2014 1:00 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, May 26, 2014 7:27 AM
Points: 71, Visits: 193
Getting ready for 70-461, and reviewing some XML... Running this query makes it seem like the two are the same... is this always the case? Or am I missing something?

IF OBJECT_ID('XMLForHomework') IS NOT NULL DROP TABLE XMLForHomework
CREATE TABLE XMLForHomework
(
ID INT PRIMARY KEY IDENTITY (1,1),
FirstName varchar(20),
LastName varchar(20),
FavoriteTeam varchar(10)
)
-- Add some stuff
INSERT INTO XMLForHomework VALUES
('Ben', 'Jamin', 'Tribe'),
('Chris', 'Smith', 'Sox'),
('Beth', 'Smith', 'Cubs'),
('Your', 'Mom', 'Yanks'),
('Your', 'Dad', 'Mets')
--
--SELECT * FROM XMLForHomework FOR XML AUTO
--SELECT * FROM XMLForHomework FOR XML RAW
SELECT * FROM XMLForHomework FOR XML RAW, ELEMENTS
--SELECT * FROM XMLForHomework FOR XML PATH('Path')
SELECT * FROM XMLForHomework FOR XML PATH, ELEMENTS
--
DROP TABLE XMLForHomework

Post #1574213
Posted Sunday, May 25, 2014 9:51 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, September 19, 2014 4:09 AM
Points: 565, Visits: 8,711
I'm not sure what you mean by "always the same." There are things that you can't do with Raw that you can with Path.

IF OBJECT_ID('XMLForHomework') IS NOT NULL DROP TABLE XMLForHomework
CREATE TABLE XMLForHomework
(
ID INT PRIMARY KEY IDENTITY (1,1),
FirstName varchar(20),
LastName varchar(20),
FavoriteTeam varchar(10)
)
-- Add some stuff
INSERT INTO XMLForHomework VALUES
('Ben', 'Jamin', 'Tribe'),
('Chris', 'Smith', 'Sox'),
('Beth', 'Smith', 'Cubs'),
('Your', 'Mom', 'Yanks'),
('Your', 'Dad', 'Mets')
--
--SELECT * FROM XMLForHomework FOR XML AUTO
--SELECT * FROM XMLForHomework FOR XML RAW
SELECT * FROM XMLForHomework FOR XML RAW, ELEMENTS
--SELECT * FROM XMLForHomework FOR XML PATH('Path')
SELECT * FROM XMLForHomework FOR XML PATH, ELEMENTS
SELECT FavoriteTeam
, FirstName as [Name/@FirstName]
, LastName as [Name/@LastName]
FOR XML Path, ELEMENTS;
--
DROP TABLE XMLForHomework

This code creates a subelement for each row that has the name called Name, with two attributes. You can't do that with Raw.


Russel Loski, MCITP
Post #1574393
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse