SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


OPENXML only give me NULL values, why ?


OPENXML only give me NULL values, why ?

Author
Message
onlo
onlo
Mr or Mrs. 500
Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)

Group: General Forum Members
Points: 542 Visits: 623
I typed the following statements :

CREATE TABLE ID (CHAR(4))
DECLARE @docHandle INT
DECLARE @xmlDocument XML
SET @xmlDocument=N'

'
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlDocument
INSERT ID SELECT * FROM OPENXML(@docHandle, N'/IDs/ID') WITH ID

I list out the content of the ID table, there is just 2 NULL records.
Why ?
Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3742 Visits: 24466
Your XML doesn't show up, also I think WITH "tablename" will only pick up attributes.
Either change to this

INSERT ID SELECT * FROM OPENXML(@docHandle, N'/IDs/ID') WITH (ID char(4) 'text()')



or use the 'nodes' function

INSERT ID  
SELECT r.value('.','char(4)') AS ID
FROM @xmldocument.nodes('/IDs/ID') AS x(r)



____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




onlo
onlo
Mr or Mrs. 500
Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)

Group: General Forum Members
Points: 542 Visits: 623
Dear Mark,

My example was quoted from Microsoft's Web site :
http://msdn2.microsoft.com/en-us/library/ms191268.aspx

But you said : "Your XML doesn't show up, also I think WITH "tablename" will only pick up attributes."

I think what you said was correct.

Thanks a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search