Thursday 15 May 2014

how to insert row(s) from xml file to sql table -


Hello I'm new to using XML file,
I want to insert a file ICD.XML in SQL Tables Try XML file format like

  & lt; Letter & gt; & Lt; Title & gt; # & Lt; / Title & gt; & Lt; MainTerm> & Lt; Title & gt; 1-propanol & lt; / Title & gt; & Lt; Cell collo = "2" & gt; T 51.3X1 & lt; / Cell & gt; & Lt; Cell collo = "3" & gt; T 51.3X2 & lt; / Cell & gt; & Lt; Cell call = "4" & gt; T51.3X3 & lt; / Cell & gt; & Lt; Cell call = "5" & gt; T51.3X4 & lt; / Cell & gt; & Lt; Cell call = "6" & gt; - & lt; / Cell & gt; & Lt; Cell call = "7" & gt; - & lt; / Cell & gt; & Lt; / MainTerm> & Lt; MainTerm> & Lt; Title & gt; 2-propanol & lt; / Title & gt; & Lt; Cell collo = "2" & gt; T 51.2X1 & lt; / Cell & gt; & Lt; Cell collo = "3" & gt; T 51.2 x 2 & lt; / Cell & gt; & Lt; Cell call = "4" & gt; T51.2X3 & lt; / Cell & gt; & Lt; Cell collo = "5" & gt; T 51.2 x 4 & lt; / Cell & gt; & Lt; Cell call = "6" & gt; - & lt; / Cell & gt; & Lt; Cell call = "7" & gt; - & lt; / Cell & gt; & Lt; / MainTerm>   

I use this code

  declare @ xml select XML @ xml = CONVERT (XML, Bulkcolumn, 2) Insert the X set in the form of the ArrayBox (Bulk 'File Path', SINGLE_BLOB) in the External Dbo. TastexML (C1, C3, C4, C5, C6, C7) p. Value ('C1 [1]', 'VAARAr (AS) C1, P. value (' C2 [1] ',' VAARAAR (100) ') ASC2, P. Value (' C3 [1] ], 'VAARAAR (100)', ASC3, P (C4 [1] ',' VAARAAR (100) ', ASC4, P. Value (' C5 [1] ',' VAARAAR (100) AS 'C5, P. Value (' C6 [1] ',' VARCHAR (100) 'AS-C6, P. Value (' C7 [1] ',' Vichareesh (100) ') AS 7, @ XML.Nodes ('/ letter / title') propertyfid (P)   

but I have error in syntax, you can help me

  • Add a closing element "Letter"
  • If you have any other way thnx

  • Remove the comma after the last column in the column list
  • Li>
  • Modify the XQuery in the nodes ('/ letter / mainTerm') in the method < / Li>
  • Add the condition for each value in the .value method

    If there is no OBJECIDID ('dbo. Testxml') then tap drop table debob. TestX ML table debo.TestxML (10), C2 Vertex (10), C3 curve (10), C4 varchar (10), c5 varchar (10), c6 varchar (10), c7 varchar (10)) DECLARE @ xml xml = '& lt; Letter & gt; & Lt; Title & gt; # & Lt; / Title & gt; & Lt; MainTerm> & Lt; Title & gt; 1-propanol & lt; / Title & gt; & Lt; Cell collo = "2" & gt; T 51.3X1 & lt; / Cell & gt; & Lt; Cell collo = "3" & gt; T 51.3X2 & lt; / Cell & gt; & Lt; Cell call = "4" & gt; T51.3X3 & lt; / Cell & gt; & Lt; Cell call = "5" & gt; T51.3X4 & lt; / Cell & gt; & Lt; Cell call = "6" & gt; - & lt; / Cell & gt; & Lt; Cell call = "7" & gt; - & lt; / Cell & gt; & Lt; / MainTerm> & Lt; MainTerm> & Lt; Title & gt; 2-propanol & lt; / Title & gt; & Lt; Cell collo = "2" & gt; T 51.2X1 & lt; / Cell & gt; & Lt; Cell collo = "3" & gt; T 51.2 x 2 & lt; / Cell & gt; & Lt; Cell call = "4" & gt; T51.2X3 & lt; / Cell & gt; & Lt; Cell collo = "5" & gt; T 51.2 x 4 & lt; / Cell & gt; & Lt; Cell call = "6" & gt; - & lt; / Cell & gt; & Lt; Cell call = "7" & gt; - & lt; / Cell & gt; & Lt; / MainTerm> & Lt; / Letter & gt; 'INSERT dbo.TestXML (C1, C2, C3, C4, C5, C6, C7) SELECT p.value (' (title) [1] ',' VARCHAR (100) ') AS 1, p. Value ('(cell ASC2, p.value (' (cell) [@ coal = 3] [1] ',' vĂ¡arar (100) '' ASC3, P. value ('(cell) [@ col = 4] [1] ',' VARCHAR (100) '' ASC4, P. value ('(cell) [@ col = 5] [1]', '' ASC5, P. value ('( Cell) [@ call = 6] [1] ',' VAARAR (100) 'ASC6, P. value (' (cell) [@ col = 7] [1] ',' VARCHAR (100) ') See examples from AS7 @ xml.nodes ('/ letter / mainTerm') propertyfid (P) SELECT * FROM dbo.TestXML



  • No comments:

    Post a Comment