From the database there is a column which contains xml data in the format like:
<old_template_code> something </old_template_code><old_template_name> new
code</old_template_name><new_template_code>BEVA24M</new_template_code>
How can I extract the values from the xml and make a column for each of the different xml values? For example I would like to do something like:
select EXTRACTVALUE(table.column, table.column)
but the latter doesn't work for me.
Related
I have a XML data column in a SQL Server table. There are more than 5000 elements in the XML. I intended to make a table out of that XML formatted column.
As far as I'm aware, SQL has a limitation that a table can only have 1024 columns. How will I flatten the file so that it may be used for reporting?
I have data in table as below where value column data is quite big, like unstructured text:
http://s3.pdfconvertonline.com/convert/p3r68-cdx67/78gbs-hvj2r.html
The characters which you find in date like & and   are present and this is just for 2 small records, actual data is quite bigger which is why i use pivot xml as the IDs are 300 in real data set.
The Heading and Value columns were initially HTML data for each ID which is now split on basis of heading and corresponding value in html using xmltype parsing.
Now we have data in the 2 columns split.
I need to pivot this, i.e. the Heading column values which are constant for ever id to become column headers and the respective values to come below as rows.
When I run the pivot query it throws error:
select *
from data
pivot xml (max(id) for heading in (select heading from data));
An error occurs in XML parsing.
Entity reference is not well formed.
XML Parser returned an error while trying to parse the document.
Check if document to be parsed is valid.
Could the error be because of these special characters?
For example I have table "BigApple" with three columns.
first column includes numbers
second column includes some text
third column includes XML files.
My question is: how to get to the third column of the specific values for a particular tag?
Use one of the XML methods on XML column https://msdn.microsoft.com/en-us/library/ms190798.aspx
In fact, if you have the same kind of XML data in the third column you can read specific tag values easily.
Please refer to examples on SQL XML query using a single XML variable
and example to query XML column in SQL database table using CROSS APPLY
Mao, how do you expect to get an answer which really helps you without showing your data? It can be trivial 'til really tricky to get data from an XML. Do you need only one particular tag? Or are there several data? Nested data?
One example for a trivial read might be this:
CREATE TABLE #tmpTbl(Number INT, SomeText VARCHAR(100),SomeXML XML);
INSERT INTO #tmpTbl VALUES
(1,'Test1','<root><a>xmlA1</a><b>xmlB1</b></root>')
,(2,'Test2','<root><a>xmlA2</a><b>xmlB2</b></root>');
SELECT Number
,SomeText
,SomeXML.value('(/root/a)[1]','varchar(10)') AS Tag_a
FROM #tmpTbl;
GO
DROP TABLE #tmpTbl;
The result
Number SomeText Tag_a
1 Test1 xmlA1
2 Test2 xmlA2
I have a table that houses a bunch of data in an XML field. I can get to the data and display what I need in the select statement, but I also need to use that to compare to another table that houses a translation I am trying to do. Is there a way to compare the value being returned from the XML data to a string value that exists in another table?
The code in my select to return the XML data is:
prv.reported_attributes.value('(/row[#ATTRIBUTE="FIELD"][1])/#VALUE', 'varchar(5)')
I need to compare that text output to another table, but I keep getting NULL like the values I am trying to compare do not match. I have confirmed they do in fact have matches.
I have a table that stores an XML data type. I'm trying to compare what is in the table against data that will be inserted.
How do I Query and compare a sql XML data type to a table XML column?
I converted the data column to a varchar and did a string compare.
In Oracle you could compare CLOB's by using dbms_lob.compare
I converted the data column to a varchar and did a string compare.