[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Evaluate XML data in a Text Column SQL 2000 db with OPENQuery

Posted on 2007-10-03
2
Medium Priority
?
1,094 Views
Last Modified: 2012-08-13
I have a fixed set of nodes within my XML that is stored inside of my table/column.

This is my t-sql:  
DECLARE @idoc int
DECLARE @doc varchar(8000)

set @doc = '<specialInstruction><section id="customerSuppliedShippingAccount"></section><section id="customerCare"></section><section id="finance">11x17 and cutting. 4 cuts @ $3.00 per 50 sheets. If binding is chosen, add additional charges. </section><section id="production.kitting"></section><section id="production.inventory"></section><section id="production.finishing">Cut document at crop marks to final size of 13" x 5".</section><section id="production.prePress">Layout document at crop marks to final size of 13" x 5".</section><section id="production.printJob">The final size of this document will be 13x5. Prepress will provide a replacement file.</section><section id="production.shipping"></section><section id="production.packaging"></section><section id="production.general"></section></specialInstruction>'

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

SELECT    *
FROM       OPENXML (@idoc, 'specialInstruction/section id',1)
            WITH (
customerSuppliedShippingAccount varchar(1000),
customerCare varchar(1000),
finance varchar(1000),
[production.kitting] varchar(1000),
[production.inventory] varchar(1000),
[production.finishing] varchar(1000),
[production.prePress] varchar(1000),
[production.printJob] varchar(1000),
[production.shipping] varchar(1000),
[production.packaging] varchar(1000),
[production.general] varchar(1000)
)

I get and error "Msg 6603, Level 16, State 1, Line 8
XML parsing error: Expected token 'eof' found 'NAME'.

specialInstruction/section -->id<--"

When I remove the section id I get nulls.

I know that I'm close, what am I missing?

TIA

__Stephen
0
Comment
Question by:srussell705
2 Comments
 
LVL 6

Accepted Solution

by:
itdrms earned 2000 total points
ID: 20011552
SELECT    *
FROM       OPENXML (@idoc, 'specialInstruction/section',1)
            WITH (SectionID varchar(1000) '@id',SectionText varchar (1000) '.')

will return a 2 x 11 table.  column for the sectionid and another for its associated text
0
 
LVL 1

Author Comment

by:srussell705
ID: 20013819
Bingo!

I appreciate that.

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

872 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