xquery-sql

What is the significance of [1] in Xquery

混江龙づ霸主 提交于 2019-12-07 13:25:31
问题 I am new to xquery in SQL Server. I have often come across xquery expressions using [1] with attributes. Can somebody please explain what does it mean? Here is a example declare @aa xml set @aa='<data> <row> <Value>1</Value> <Text>Masters</Text> </row> <row> <Value>2</Value> <Text>Transactions</Text> </row> <row> <Value>3</Value> <Text>Misch. Reports</Text> </row> </data>' select a.f.value('Value[1]','varchar(50)'), -- why [1] here ? a.f.value('Text[1]','varchar(50)') -- and here too.. from

Use XQuery to get at this data

我是研究僧i 提交于 2019-12-07 11:55:12
问题 I am new to XQuery and am having some problems with it. Here is my example. I have this variable: declare @xmlDoc XML it has the following xml stored in it: <?xml version="1.0" encoding="utf-8"?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale=""> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name=

FLWOR in Sql server count number of hits

依然范特西╮ 提交于 2019-12-07 11:45:20
问题 I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in /Root/Persons/Person return <Person ID="{$count}">{$s}</Person>') The only problem here is this is not supported in SQL Server and I receive an error: Msg 9335, Level 16, State 1, Line 16 XQuery [query()]: The XQuery syntax 'at' is not supported. I've also

How to optimise the 'XQuery' SQL

青春壹個敷衍的年華 提交于 2019-12-06 07:48:17
问题 I have an XML hierarchy like this in an XML type column of a table with 10,000 records- <Root> <Elem1> <Parent1> <Separator> <Child1/> </Separator> </Parent1> </Elem1> </Root> I have a query like this - DECLARE @Root VARCHAR(50) DECLARE @Entity VARCHAR(50) DECLARE @ParentNode VARCHAR(50) DECLARE @Separator VARCHAR(50) DECLARE @ChildNode VARCHAR(50) SET @Root = 'Root' SET @Entity = 'Elem1' SET @ParentNode = 'Parent1' SET @Separator = 'separator' SET @ChildNode = 'Child1' select Parent.P.value(

XQuery: Finding rows which contain specified xml data

一笑奈何 提交于 2019-12-06 04:05:10
I have a table which contains many rows, each with a column named "RecordData" that contains XML data that I wish to search upon. Three rows worth of example xml data from this column is given below: 1: <Record> <RecordField ID="31" Name="Barcode1" DataTypeId="5" TypeName="String" Decimals="0" Format="" Mandatory="False">ABC123</RecordField> </Record> 2: <Record> <RecordField ID="15" Name="Field 1" DataTypeId="7" TypeName="Boolean" Decimals="0" Format="" Mandatory="False">true</RecordField> <RecordField ID="16" Name="Field 2" DataTypeId="5" TypeName="String" Decimals="0" Format="" Mandatory=

What is the significance of [1] in Xquery

强颜欢笑 提交于 2019-12-06 03:56:50
I am new to xquery in SQL Server. I have often come across xquery expressions using [1] with attributes. Can somebody please explain what does it mean? Here is a example declare @aa xml set @aa='<data> <row> <Value>1</Value> <Text>Masters</Text> </row> <row> <Value>2</Value> <Text>Transactions</Text> </row> <row> <Value>3</Value> <Text>Misch. Reports</Text> </row> </data>' select a.f.value('Value[1]','varchar(50)'), -- why [1] here ? a.f.value('Text[1]','varchar(50)') -- and here too.. from @aa.nodes('/data/row') as a(f) Thanks n Regards Jeremy Pridemore In this case you're saying you want the

Use XQuery to get at this data

社会主义新天地 提交于 2019-12-05 18:28:04
I am new to XQuery and am having some problems with it. Here is my example. I have this variable: declare @xmlDoc XML it has the following xml stored in it: <?xml version="1.0" encoding="utf-8"?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale=""> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="Table1"> <xs:complexType> <xs:sequence> <xs:element name="Sharedparam" type="xs:string" minOccurs="0" /

FLWOR in Sql server count number of hits

∥☆過路亽.° 提交于 2019-12-05 17:47:30
I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in /Root/Persons/Person return <Person ID="{$count}">{$s}</Person>') The only problem here is this is not supported in SQL Server and I receive an error: Msg 9335, Level 16, State 1, Line 16 XQuery [query()]: The XQuery syntax 'at' is not supported. I've also tried with let keyword and define new variable but I don't know how to increase value of that variable

Update XML field with no text in T-SQL

柔情痞子 提交于 2019-12-05 12:46:09
I've come across a problem in updating an SQL field in that what I've written works perfectly for xml nodes with a text present, however it trips up when the node is empty. <filemeta filetype="Video"> <heading>TEST</heading> <description /> </filemeta> This code works fine; UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/heading/text())[1] with "TEST"'); However this breaks; UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/description/text())[1] with "notworking!"'); Thanks for any help. This node (/filemeta/description/text())[1] does not exist in the XML

Search for multiple values in xml column in SQL

我只是一个虾纸丫 提交于 2019-12-05 11:49:00
This is my table BasketId(int) BasketName(varchar) BasketFruits(xml) 1 Gold <FRUITS><FID>1</FID><FID>2</FID><FID>3</FID><FID>4</FID><FID>5</FID><FID>6</FID></FRUITS> 2 Silver <FRUITS><FID>1</FID><FID>2</FID><FID>3</FID><FID>4</FID></FRUITS> 3 Bronze <FRUITS><FID>3</FID><FID>4</FID><FID>5</FID></FRUITS> I need to search for the basket which has FID values 1 and 3 so that in this case i would get Gold and Silver Although i've reached to the result where i can search for a SINGLE FID value like 1 using this code: declare @fruitId varchar(10); set @fruitId=1; select * from Baskets WHERE