Monday, February 20, 2012

OPENXML question

Can't get the following code to return two rows:
DECLARE @.data varchar(1000)
DECLARE @.hdoc int
select @.data = '<root><guid>a1</guid><guid>b1</guid></root>'
EXEC sp_xml_preparedocument @.hdoc OUTPUT, @.data
select *
from openxml(@.hdoc, '/root', 2)
with (guid varchar(10))
EXEC sp_xml_removedocument @.hdoc
Because you have only one root element you will only get one row.
Use
select *
from openxml(@.hdoc, '/root/guid', 2)
with (guid varchar(10) '.')
HTH
Michael
"Mark Frishman" <mfrishman_nospam@.hotmail.com> wrote in message
news:%23Bcjk7lfEHA.4092@.TK2MSFTNGP10.phx.gbl...
> Can't get the following code to return two rows:
> DECLARE @.data varchar(1000)
> DECLARE @.hdoc int
> select @.data = '<root><guid>a1</guid><guid>b1</guid></root>'
> EXEC sp_xml_preparedocument @.hdoc OUTPUT, @.data
> select *
> from openxml(@.hdoc, '/root', 2)
> with (guid varchar(10))
> EXEC sp_xml_removedocument @.hdoc
>

No comments:

Post a Comment