How to rea xml in sql 2005
-
viernes, 11 de mayo de 2012 8:09
Hi,
how to read this XML in sql 2005 and store the data into temptable.
Please help me.
'<DocumentElement>
<QuestionList>
<QuestionId>Q1000</QuestionId>
<Title>Apple /Title>
<Sequence>3</Sequence>
<MergeSequence>1</MergeSequence>
</QuestionList>
<QuestionList>
<QuestionId>Q1028</QuestionId>
<Title>Banana/Title>
<Sequence>3</Sequence>
<MergeSequence>2</MergeSequence>
</QuestionList>
<QuestionList>
<QuestionId>Q1029</QuestionId>
<Title>orange/Title>
<Sequence>3</Sequence>
<MergeSequence>3</MergeSequence>
</QuestionList>
</DocumentElement>'Output
QuestioID Title Seq MerSeq Q1000 Apple 3 1 Q1028 Banan 3 2 Q1029 Orange 3 3
Thanks
Narayanan
- Editado Narayanan vd viernes, 11 de mayo de 2012 8:13
- Editado Narayanan vd viernes, 11 de mayo de 2012 9:06
- Cambiado ErikEJMVP viernes, 11 de mayo de 2012 11:23 wrong forum (From:SQL Server Compact)
Todas las respuestas
-
viernes, 11 de mayo de 2012 11:49Usuario que responde
Try this:
DECLARE @xml XML SET @xml = '<DocumentElement> <QuestionList> <QuestionId>Q1000</QuestionId> <Title>Apple</Title> <Sequence>3</Sequence> <MergeSequence>1</MergeSequence> </QuestionList> <QuestionList> <QuestionId>Q1028</QuestionId> <Title>Banana</Title> <Sequence>3</Sequence> <MergeSequence>2</MergeSequence> </QuestionList> <QuestionList> <QuestionId>Q1029</QuestionId> <Title>orange</Title> <Sequence>3</Sequence> <MergeSequence>3</MergeSequence> </QuestionList> </DocumentElement>' SELECT q.c.value('(QuestionId/text())[1]', 'VARCHAR(10)'), q.c.value('(Title/text())[1]', 'VARCHAR(20)'), q.c.value('(Sequence/text())[1]', 'VARCHAR(20)'), q.c.value('(MergeSequence/text())[1]', 'VARCHAR(20)') FROM @xml.nodes('DocumentElement/QuestionList' ) q(c)- Propuesto como respuesta Iric WenModerator lunes, 14 de mayo de 2012 8:57
- Marcado como respuesta Iric WenModerator viernes, 18 de mayo de 2012 8:20
-
domingo, 13 de mayo de 2012 12:17
check this link this may help you
http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/
-
martes, 22 de mayo de 2012 9:50
Thanks ...
- Editado Narayanan vd martes, 22 de mayo de 2012 9:50

