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 «««123

Basics of XML and SQL Server, Part 2: Shredding XML Expand / Collapse
Author
Message
Posted Friday, March 16, 2012 8:28 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 17, 2014 10:29 AM
Points: 83, Visits: 740
Stan Kulp-439977 (3/15/2012)
My bet is that during the course of a year they lose some through mergers, bankruptcies, etc. and have to replace them. It may take a while to find suitable replacements.

I played with that data quite a bit, and I have no reason to believe that the 499 count is wrong.


I agree with that. I just wanted to confirm that someone else was also getting the 499 result set. Thanks for the follow-up and very nice article by the way. I don't usually walk through a lot of the steps in these articles but I followed this one all the way through (which is why I was concerned about the 499 results).

Again, thanks for the follow-up.
Post #1268278
Posted Friday, March 16, 2012 3:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 16, 2012 2:59 PM
Points: 3, Visits: 20
I'll look for the article..
Post #1268553
Posted Saturday, March 17, 2012 12:24 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: Yesterday @ 5:59 PM
Points: 538, Visits: 772
I think this is one of the best XML primers I've seen. Thank you for such a great article!


Post #1268612
Posted Sunday, March 18, 2012 4:27 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 8:52 PM
Points: 56, Visits: 1,046
It took me a while before I could read the article past where we generate XML with attributes and then transform it using a style sheet.

Maybe I'm missing something, but wouldn't it have been easier to use

SELECT DISTINCT * FROM [dbo].[sp500hst] AS StockData WHERE [Date] = '20090821' ORDER BY [Ticker]
FOR XML PATH('StockData'),ROOT('StockMarketData')

instead of

SELECT DISTINCT * FROM [dbo].[sp500hst] AS StockData WHERE [Date] = '20090821' ORDER BY [Ticker]
FOR XML AUTO,ROOT('StockMarketData')

followed by a transform using external processes, which, while interesting, doesn't really add much to the discussion about XML in SQL?


All my XML work uses elements not attributes (not my choice, if that matters to anyone), which may explain why this jumped out at me.
Post #1268766
Posted Sunday, March 18, 2012 6:30 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, October 20, 2014 10:05 AM
Points: 128, Visits: 920
I'm sure your way is more efficient, but I was not really focused on the most efficient way to do things when writing this tutorial.

I was interested in demonstrating how to do things in as illustrative and understandable a manner as possible.

I broke it into stages just to illustrate it better, and to prepare for the next article in which I automate the transforms in SSIS.

For me, learning how to do something new is the hard part. Once I understand it, I can figure out how to improve it on my own.
Post #1268773
Posted Sunday, March 18, 2012 6:57 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 8:52 PM
Points: 56, Visits: 1,046
Stan Kulp-439977 (3/18/2012)
...I was interested in demonstrating how to do things in as illustrative and understandable a manner as possible.

I broke it into stages just to illustrate it better...


That's exactly why I found it a bit distracting to have a whole section called 'Transform the XML document's attributes into elements' in the middle of an otherwise interesting article; While the transform stuff is interesting in its own right; it's a *bit* off-topic and didn't really help explain 'XML Shredding', which was the core of your article.

I'm looking forward to the next installment... I have some XML transforming stuff I do at a particular customer using Task Manager, I'm interested to see if there'll be any merit in using SSIS instead :)

/Ryan
Post #1268775
Posted Monday, July 16, 2012 1:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 4, 2013 8:50 AM
Points: 1, Visits: 63
This article was a great help.

My relational mindset is stubbornly resisting the hierarchical nature of xml and I was having a rough time with even the simplest operations. This article helped me shred a fairly complex xml document that I've been having issues with. My only problem now is that it only seems to be bring in the first instance of a node sequence (ie - if a productID can have multiple itemIDs, my shred only brings in the first ItemID). I suspect this is where the "cross apply" operator comes into play and I'm sure I'll figure it out with some practice.

I'll never be an xml guru, but with the information in this article I no longer consider it an achilles heel. Thanks!
Post #1330357
Posted Monday, December 31, 2012 6:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 31, 2012 7:13 PM
Points: 6, Visits: 6
** Update**
I went through the example as presented and even though it worked it generated error messages (SQL 2012).
I changed the script to what I thought it should be and the errors went away.
Thanks for taking the time to write the article. I understand the material better than I did yesterday after reading about this topic in one of my books.
** End Update **

Did you make a mistake in the openxml example?
I ask this because you have the following:

EXEC sp_xml_prepareDocument @hdoc OUTPUT, @Doc

So now I have to access the xml data using @hdoc right?
But you do it through @idoc in the following statement.

FROM Openxml (@iDoc,'//StockMarketData/StockData ')

You refer the reader to a Microsoft example which is:

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

OPENXML (@idoc, '/ROOT/Customer',1)

So it would seem that your openxml statement should be:

FROM Openxml (@hdoc, '//StockMarketData/StockData' @iDoc)

Am I correct or am I missing something because I do not understand how you can access the xml data using
@idoc which you initialize to a value of 1? Struggling a little with this.
Post #1401537
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse