Wednesday, March 7, 2012

Help with OPENXML

Hi all,
I have a XMLString Like given below :
<PF OrderID="1234">
<CF>Computer</CF>
<CF>Phone</CF>
<CF>Modem</CF>
</PF>
My Question is
how do I insert into a SqlServer table havinf the Following
fields:
ORderID ItemNAme
After using OPEnXMl the table should look like this
ORderID ItemNAme
1234 Computer
1234 Phone
1234 Modem
Any thoughts on this
Thanks in Advance
..NetHelpWanted
Try this:
DECLARE @.x nvarchar(2000)
SET @.x = '<PF OrderID="1234">
<CF>Computer</CF>
<CF>Phone</CF>
<CF>Modem</CF>
</PF>'
DECLARE @.h int
EXEC sp_xml_preparedocument @.h OUTPUT, @.x
SELECT * FROM OPENXML (@.h, 'PF/CF', 2)
WITH
(OrderID int '../@.OrderID',
ItemName nvarchar(20) './text()'
)
EXEC sp_xml_removedocument @.h
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
www.microsoft.com/mspress/books/6137.asp
".NetHelpWanted" <sasijrao@.gmail.com> wrote in message
news:FCA22802-A90B-4C2C-997A-81B90186B580@.microsoft.com...
Hi all,
I have a XMLString Like given below :
<PF OrderID="1234">
<CF>Computer</CF>
<CF>Phone</CF>
<CF>Modem</CF>
</PF>
My Question is
how do I insert into a SqlServer table havinf the Following
fields:
ORderID ItemNAme
After using OPEnXMl the table should look like this
ORderID ItemNAme
1234 Computer
1234 Phone
1234 Modem
Any thoughts on this
Thanks in Advance
..NetHelpWanted

No comments:

Post a Comment