xquery-sql

Syntax for xquery with namespace in the node

白昼怎懂夜的黑 提交于 2020-01-06 16:26:01
问题 We are trying to get IdValue from sql query. We are using sql server 2005. DECLARE @MyXML XML SET @MyXML = '<Candidate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15"> <CandidateProfile> <ProfileId> <IdValue>9499063</IdValue> </ProfileId> </CandidateProfile> </Candidate>' SELECT @MyXML.value('Candidate[1]/CandidateProfile[1]/ProfileId[1]','varchar(10)') AS Id This is not working because of the name

Syntax for xquery with namespace in the node

天大地大妈咪最大 提交于 2020-01-06 16:25:18
问题 We are trying to get IdValue from sql query. We are using sql server 2005. DECLARE @MyXML XML SET @MyXML = '<Candidate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15"> <CandidateProfile> <ProfileId> <IdValue>9499063</IdValue> </ProfileId> </CandidateProfile> </Candidate>' SELECT @MyXML.value('Candidate[1]/CandidateProfile[1]/ProfileId[1]','varchar(10)') AS Id This is not working because of the name

Delete xml node from SQL Server 2008 r2 table column based on attribute value

自作多情 提交于 2020-01-06 04:00:26
问题 I have an xml structure as follows <DifficultyRule xmlns="urn:gjensidige:processguide:201201"> <Id>fc39f423-05c0-4de9-ae46-12fe3c0c279b</Id> <Code>5595e558-7d10-4767-86dc-5d16f24b8151_Code</Code> <Author /> <Updated>9/5/2012</Updated> <Sequence>0</Sequence> <FromControls> <Control> <Code>oiuyui</Code> <Id>70579cbe-c0b5-4b49-a7b8-6201af388f59</Id> <FilterValues> <FilterValue xmlns:p5="urn:gjensidige:processguide:201201" p5:Id="b897f3ac-b40f-4b96-b438-eb156a26457e" p5:Code="e" p5:LookupId=

shredding xml recursively into the database

社会主义新天地 提交于 2020-01-02 04:54:06
问题 I have the following XML data and the Element table. DECLARE @input XML = '<root> <C1> <C2> <C3> <C4>data1</C4> </C3> </C2> <C2> <C3>data2</C3> </C2> </C1> <D1> <D2>data3</D2> <D2>data4</D2> </D1> </root>' Element table:( this is just an example so can be changed to match an appropriate solution.) CREATE TABLE Element ( elementId INT IDENTITY PRIMARY KEY, elementName VARCHAR (200) NOT NULL, parentId INT, data VARCHAR(300) ); According to @input the root element is parent of C1 and D1, then C1

Sort XML Attributes in SQL

放肆的年华 提交于 2019-12-25 05:13:34
问题 How to sort XML Attributes in SQL? for example for this XML: <books><book b='' c='' a=''/></books> I want: <books><book a='' b='' c=''/></books> 回答1: From http://msdn.microsoft.com/en-us/library/ms187107%28v=sql.90%29.aspx: The order of the XML attributes is not preserved. When you query the XML instance stored in the xml type column, the order of attributes in the resulting XML may be different from the original XML instance. So even if you could figure out a way of sorting the attributes,

querying an XML list in sql server using Xquery

瘦欲@ 提交于 2019-12-25 00:08:14
问题 I have a table in SQL server that is used to store submitted form data. The form fields for each submission are dynamic so the collected data is stored as name value pairs in an XML data column called [formdata] as in the example below... This works fine for collecting the required information but I now need to render this data to a flat file or an excel document for processing by human staff members and im wondering what the best way of doing this would be using Xquery so that the data is

sql xml order processor

流过昼夜 提交于 2019-12-24 10:12:42
问题 I was wondering if anyone could point me to a tutorial or give me suggestions on processing an XML "Request For Quote" document. Using SQL Server 2005. For example: <MyQuote> <Header> <Customer>XYZ</Customer> <Material>Wood&</Material> <Header> <LineItems> <Line> <Quantity>32</Quantity> <Model>Chair 350</Model> <Color>Red</Color> </Line> . </LineItems> </MyQuote> Just getting my feet wet with XQuery. I need to shred this doc into individual Line Items, identify each one with a number,

Need a complex Xpath using sibling children, ancestors

▼魔方 西西 提交于 2019-12-23 20:05:54
问题 I need to find attribute values based on other values pulled from parent's/grand-parent's sibling's children. I think it's going to take 2 different expressions. So given the following XML (which is derived from a log file that can be thousands of lines long): <p:log xmlns:p="urn:NamespaceInfo"> <p:entries> <p:entry timestamp="2012-12-31T09:39:25"> <p:attributes> <p:attrib name="Position" value="1B2" /> <p:attrib name="Something" value="Something_else" /> </p:attributes> <p:msg> </p:msg> </p

Separating XML values with the same tags into different rows SQL Server

牧云@^-^@ 提交于 2019-12-23 17:43:42
问题 I have an XML File which I am trying to parse. The XML was created through Excel using Save as XML Because the XML file was created from Microsoft Excel, it has this header: <?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC

SQL Server XML add attribute if non-existent

落爺英雄遲暮 提交于 2019-12-23 16:55:07
问题 I am trying to add an attribute if it does not exist. It should be simple, but I am new to XML XPath/XQuery/etc., so excuse my ignorance. I want to be able to pass XML data and modify it... ALTER FUNCTION [dbo].[ConvertXmlData](@xmlData XML) RETURNS XML AS BEGIN RETURN @xmlData.<something here> END If I pass data like: <something> this is sample data <xxx id="1"/> and <xxx id="2" runat="server" />. More <yyy id="3" /> </something> I would like <something> this is sample data <xxx id="1" runat