xquery-sql

How to check VARCHAR(n) for well-formed XML before CAST/CONVERT

℡╲_俬逩灬. 提交于 2021-01-27 06:23:08
问题 My company has a logging table containing a VARCHAR(N) column in which a string is placed that is supposed to be XML, but as it turns out it is not always well-formed. In order to perform analysis on the logging (to identify error trends, etc.), I have been using a LIKE statement. However, this is remarkably slow. Recently, I discovered that SQL Server supports XQuery, so I started playing with it. The problem I'm running into is that I can't figure out a way to handle CAST/CONVERT errors

The best way to extract data from xml with xquery

白昼怎懂夜的黑 提交于 2020-01-14 18:48:15
问题 Consider the following xml: <Persons num="3"> <Person age="5" /> <Person age="19" /> </Persons> There is a need to extract this xml into a relational table: Persons table (Age1 int, Age2 int, Age3 int , Age4 int) Parsing has to satisfy the following constraints: all persons with age >=18 must be assigned to columns with smallest column number and the value has to be 18 if the age of the person is not given it is equal to 18 all persons with age <18 must follow if there are less than 4 persons

The best way to extract data from xml with xquery

青春壹個敷衍的年華 提交于 2020-01-14 18:47:12
问题 Consider the following xml: <Persons num="3"> <Person age="5" /> <Person age="19" /> </Persons> There is a need to extract this xml into a relational table: Persons table (Age1 int, Age2 int, Age3 int , Age4 int) Parsing has to satisfy the following constraints: all persons with age >=18 must be assigned to columns with smallest column number and the value has to be 18 if the age of the person is not given it is equal to 18 all persons with age <18 must follow if there are less than 4 persons

T-SQL, XQuery Invalid Column

拈花ヽ惹草 提交于 2020-01-14 13:37:09
问题 I'm just learning XQUERY and trying to accomplish what I thought would be very simple. Here's my T-SQL code: DECLARE @XML xml set @xml = '<resultsets><AppVersion>13.0</AppVersion></resultsets>' -- Code below is wrong select ResultSets.AppVersion.query('AppVersion').value('.', 'varchar(100)') as AppVersion from @XML.nodes('/resultsets/AppVersion') ResultSets(AppVersion) I cannot figure out exactly how to query that inner element, appversion. I'm not getting any errors, but I'm unable to return

SQL XQuery command to recursively get descendants of same type

吃可爱长大的小学妹 提交于 2020-01-14 04:26:37
问题 I'm new to XQuery in SQL but I'm understanding the basics of getting nodes and the values of the queries. My issue now is handling a hierarchy of unknown depth. The relationship is Contract -> Project -> Lines ; and looks something like this: <ZEstimateContract xmlns="http://schemas.datacontract.org/2004/07/Zeller.Gp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i1"> <Name xmlns="http://schemas.datacontract.org/2004/07

Using SQL to transpose/flatten XML structure to columns

核能气质少年 提交于 2020-01-10 19:35:31
问题 I am using SQL Server (2008/2012) and I know there are similar answers from lots of searching, however I can't seem to find the appropriate example/pointers for my case. I have an XML column in a SQL Server table holding this data: <Items> <Item> <FormItem> <Text>FirstName</Text> <Value>My First Name</Value> </FormItem> <FormItem> <Text>LastName</Text> <Value>My Last Name</Value> </FormItem> <FormItem> <Text>Age</Text> <Value>39</Value> </FormItem> </Item> <Item> <FormItem> <Text>FirstName<