Solved

How to correct the XPath Query in OpenXML statement to get the state for each row.

Posted on 2010-08-25
3
303 Views
Last Modified: 2012-05-10
I am having trouble pulling the "StateProvCd" value for each RatingClassificationCd in the following script.  Have been playing with the Xpath and it always returns "IN" for both rows instead of "IN" for the first row and "IL" for the second row.


DECLARE @idoc int



EXEC sp_xml_preparedocument @idoc output, '<MainElement>

		<LineBusiness id="12345">

 		<LOBCd>WORK</LOBCd> 

		<RateState>

 			<StateProvCd>IN</StateProvCd> 

		<LocInfo>

			<RateClass id="abc">

  			<RatingClassificationCd>1234</RatingClassificationCd> 

  			<Exposure>100</Exposure> 

			<RatingClassificationDesc>CLASS TEST 1</RatingClassificationDesc>

  			</RateClass>

  		</LocInfo>

  		</RateState>

		<RateState>

  			<StateProvCd>IL</StateProvCd> 

		<LocInfo>

			<RateClass id="def">

  			<RatingClassificationCd>5678</RatingClassificationCd> 

  			<Exposure>500</Exposure> 

  			<RatingClassificationDesc>CLASS TEST 2</RatingClassificationDesc>  

  			</RateClass>

  		</LocInfo>

  		</RateState>

  		</LineBusiness></MainElement>'



			

SELECT RatingClassificationCd, RatingClassificationDesc, Exposure, StateProvCd

FROM   OPENXML (@idoc, '/MainElement/LineBusiness/RateState/LocInfo/RateClass', 3)

						WITH (StateProvCd				char(2) '../../../RateState/StateProvCd',

							 RatingClassificationCd 		char(5) 'RatingClassificationCd', 

							 RatingClassificationDesc 	varchar(250) 'RatingClassificationDesc',

							 Exposure					numeric(18,0) 'Exposure'							 

							) 





EXEC sp_xml_removedocument @idoc

Open in new window

0
Comment
Question by:EIHI-IT
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
grepll earned 500 total points
ID: 33521907
This should work:
WITH (StateProvCd char(2) 'ancestor::RateState/StateProvCd',

Open in new window

0
 

Author Comment

by:EIHI-IT
ID: 33521947
Thank You!
0
 
LVL 3

Expert Comment

by:grepll
ID: 33522045
Welcome.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now