sqlxml

Sql XML Path with different children

主宰稳场 提交于 2019-12-12 17:19:19
问题 I have done a lot of XML PATH statements, but this one escapes me or might not even be possible with multiple different children. The end result should look like this <Process> <TaskList> <SqlTask Name="Get Report Parameters"> <StoredProcName>GetReportParameters</StoredProcName> <ConnectionName>Local</ConnectionName> <DataTableName>DistributionList</DataTableName> <Parameters> <Parameter> <Name>ReportName</Name> <Value>TheReprot</Value> <Type>String</Type> </Parameter> </Parameters> </SqlTask

How to pass a variable into XPath of XQuery in an SQL statement

那年仲夏 提交于 2019-12-12 12:32:13
问题 Scenario: I have an xml column in MSSQL database which I have to parse the XML data of that cell using XQuery . Xml content : <AnchoredXml xmlns="urn:schema:Microsoft.Rtc.Management.ScopeFramework.2008" SchemaWriteVersion="2"> <Key ScopeClass="Global"> <SchemaId Namespace="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" ElementName="Topology" /> <AuthorityId Class="Host" InstanceId="00000000-0000-0000-0000-000000000000" /> </Key> <Dictionary Count="1"> <Item> <Key /> <Value

Query results same when using xml raw,element and xml path

自古美人都是妖i 提交于 2019-12-12 04:56:43
问题 I am using sql-server 2012: I have query like this: CREATE TABLE #XmlTestTable ( ID INT PRIMARY KEY IDENTITY(1,1), FirstName VARCHAR(20), LastName VARCHAR(20) ) INSERT INTO #XmlTestTable (FirstName,LastName) VALUES ('John','Doe'), ('Jane','Doe'), ('Brian','Smith'), ('Your','Mom') SELECT * FROM #XmlTestTable FOR XML RAW, ELEMENTS --1 SELECT * FROM #XmlTestTable FOR XML PATH --2 Result of 1: <row> <ID>1</ID> <FirstName>John</FirstName> <LastName>Doe</LastName> </row> <row> <ID>2</ID> <FirstName

Function for renaming an element in SQL Server XML

。_饼干妹妹 提交于 2019-12-11 15:52:35
问题 I'm trying to create a function able to rename an element within XML columns. The function should be something as create function dbo.fnRenameElement( @doc xml , @parentElementPath nvarchar(MAX) , @oldElementName nvarchar (255) , @newElementName nvarchar (255) ) returns ... (whatever, not really interested actually) Something I would use in this way Select dbo.fnRenameElement(MyTable.MyXmlColumn, 'some/xml/path/', 'ElementNameToReplace', 'NewElementName') Where ... I had a look at this answer

XPath1 at SQL/XML, count elements returns empty

倾然丶 夕夏残阳落幕 提交于 2019-12-11 13:55:18
问题 I am using PostgreSQL 9, that adopts XPath-1 for the SQL/XML standard cumpliance. This query is ok, returns the expected data: SELECT xpath('//img',xhtm) FROM t but this other one, to count img elements, returns empty (!), SELECT xpath('count(//img)',xhtm) FROM t NOTE 1: a xhtm field content sample, <html><p>Hello! <img src="1.png"/></p><img src="2.jpg"/></html> NOTE 2: of course array_length(xpath('//img',xhtm),1) show the count result, but it is not a XPath counting. NOTE 3: I don't know if

Swapping data between two XML files in sql script?

限于喜欢 提交于 2019-12-11 12:48:18
问题 I have a column in one of my data base tables that holds xml files. However, these files have tags inside them that need to be swapped, is there a way to automate this with a sql script? <ViewcenterLayout> <viewcenter_config> <gl_type>EStop</gl_type> <data_access> <access_as>INPUT</access_as> <access_id>1391</access_id> <parent_id>0</parent_id> <server_id>17</server_id> <subsystem>0</subsystem> </data_access> <data> <dimension x="1" y="1" z="1" /> <curve_info ir="0" or="0" degree="0" />

XML SQL query Output format issue

亡梦爱人 提交于 2019-12-11 11:58:09
问题 My SQL query is: select MedicalHeightValue, MedicalWeightValue from TableA My column names & values are: MedicalHeightValue(67), MedicalWeightValue(220) Output should be like: <HealthAttribute> <Identifier>MedicalHeightValue</Identifier> <Value>67</Value> </HealthAttribute> <Healtttribute> <Identifier>MedicalWeightValue</Identifier> <Value>220</Value> </HealthAttribute> 回答1: Try something like this: ;WITH CteData AS ( SELECT 'MedicalHeightValue' AS 'Identifier', MedicalHeightValue AS 'Value'

SQL Select XML nodes, parametrize node number

本小妞迷上赌 提交于 2019-12-11 09:48:47
问题 I'm selecting data from a XML document, however I need to loop through each child node perform some actions on them. At present I have a while exists loop around the select but don't know how to parametrize the node number. I understand the below isn't right but would appreciate it if someone could point out the best way to parametrize the node selection. Thanks. DECLARE @nodeCount varchar(1) = '1' WHILE EXISTS (SELECT table.value('(Info/Data/DataInfo/Type/node())[' + @nodeCount + ']',

XSD to SQL Server conversion

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:24:38
问题 I have a question in regards to the SQLXML for SQL Server. My assignment is to convert an XSD file so that it magically "becomes" tables in the SQL Server database. I've looked around everywhere, on all the links I could possibly find, but nothing clicks. Everything is like a half-step of what I need to achieve. I am not too familiar with Visual Studio, haven't done much else than running database queries and all the stuff one likes to do in a SQL Server database. Except for XML. I figured

SQL Server XML with dynamic arguments

☆樱花仙子☆ 提交于 2019-12-11 05:46:17
问题 I have the following table called 'mdx' yearnumber yearstart yearend weeknumber quantity 1 11-22-15 11-19-16 1 1826 1 11-22-15 11-19-16 2 1225 1 11-22-15 11-19-16 3 452 1 11-22-15 11-19-16 4 276 1 11-22-15 11-19-16 5 673 1 11-22-15 11-19-16 6 1986 1 11-22-15 11-19-16 7 3806 1 11-22-15 11-19-16 8 3608 1 11-22-15 11-19-16 9 3841 1 11-22-15 11-19-16 10 3356 1 11-22-15 11-19-16 11 3436 1 11-22-15 11-19-16 12 3437 1 11-22-15 11-19-16 13 3611 1 11-22-15 11-19-16 14 3354 1 11-22-15 11-19-16 15 3743