I stored my data in XML format in SQL server, in this way
**<Column Name="GROSS" DataType="float" Value="939760" />**
but somehow one column name (GROSS) in my XML data is stored twice, now I want to remove/rename one of them.
Below are screenshots of my database view:
Table view
XML view
This it what I tried, but it only changed the value, it did not rename the column name.
update Aquara7bc772839.EmpTransaction set TransactionFieldDetails.modify('replace value of (/PayDetails/Column[#Name="LEV_ENCASHRATE"]/#Value)[1] with "796.00"') WHERE Id = 276620;
I have highlighted my column names in above image link please check
I want to remove or rename one column.
You can use the XML.modify() method with a delete node instruction...
declare #EmpTransaction table (
Id int not null,
TransactionFieldDetails xml
);
insert #EmpTransaction values (
276620,
N'<PayDetails>
<Column Name="GROSS" DataType="float" Value="939760" />
<Column Name="GROSS" DataType="float" Value="939760" />
</PayDetails>'
);
update #EmpTransaction
set TransactionFieldDetails.modify('delete /PayDetails/Column[#Name="GROSS"][2]')
where Id = 276620;
select * from #EmpTransaction;
Which gives you...
<PayDetails>
<Column Name="GROSS" DataType="float" Value="939760" />
</PayDetails>
Note that the node index is 1-based, i.e.: Column[#Name="GROSS"][1] would remove the first GROSS node, Column[#Name="GROSS"][2] removes the second GROSS node.
As to how you got two GROSS values in the first place ... whatever created the XML for you probably lists the GROSS column twice.
For your next question: Please do not poste pictures. Best was, to provide a MCVE (a stand-alone sample to reproduce your issue).
You can try something along this:
This is such a stand-alone sample
DECLARE #mockupTable TABLE(ID INT IDENTITY, YourXml XML);
INSERT INTO #mockupTable VALUES
(N'<PayDetails>
<Column Name="blah" DataType="string" Value="Some blah" />
<Column Name="GROSS" DataType="float" Value="1.1" />
<Column Name="Another" DataType="string" Value="One more" />
<Column Name="GROSS" DataType="float" Value="1.2" />
</PayDetails>')
,(N'<PayDetails>
<Column Name="blah" DataType="string" Value="Some blah" />
<Column Name="GROSS" DataType="float" Value="2.0" />
<Column Name="Another" DataType="string" Value="One more" />
<Column Name="GROSS" DataType="float" Value="2.0" />
</PayDetails>');
--This query will first check, if there are different values for GROSS within one XML. This might be a reason to look a bit closer before deleting them.
SELECT t.ID
,t.YourXml
FROM #mockupTable t
WHERE t.YourXml.value('count(distinct-values(/PayDetails/Column[#Name="GROSS"]/#Value))','int')>1;
--And this statement will return each <Column> just once per name (always the first of its kind)
UPDATE #mockupTable SET YourXml=YourXml.query(N'
<PayDetails>
{
for $elmt in distinct-values(/PayDetails/Column/#Name)
return /PayDetails/Column[#Name=$elmt][1]
}
</PayDetails>
');
--Check the output
SELECT * FROM #mockupTable
The idea in short:
With the Xpath /PayDetails/Column[#Name="GROSS"] we are reducing the observed set to columns, where the attribute Name equals GROSS. distinct-values() is a XQuery-function returning each value in a list just once. So we can use count() to check, if there are differing values for GROSS within one XML.
The UPDATE uses XQuery's FLWOR abilities. We use again distinct-values to get all values for Name within <Column>. Then we return just the first (see the [1]) for each name.
UPDATE: Check for doubled elements
With this query you can run through your whole table to search for any non-unique column name per XML:
SELECT t.YourXml.query(N'
for $elmt in distinct-values(/PayDetails/Column/#Name)
return <NameCount Name="{$elmt}" Count="{count(/PayDetails/Column[#Name=$elmt])}"/>
').query('/NameCount[#Count>1]')
FROM #mockupTable t;
Related
I have an xml field in my table : XmlDoc which has various tags.. but I need to delete a particular value from a tag rather than deleting whole tag itself.
I have already tried using
update table
set XmlDoc.modify('delete //DeliveryMechanism//Address//text()[contains("abc#gmail.com")]')
but it deletes all the value from the tag but I need to remove only abc#gmail.com"
<DeliveryMechanism>
<ID>1</ID>
<Name>Email</Name>
<Description />
<IsActive>false</IsActive>
<Address>def#gmail.com,abc#gmail.com,hij#gmail.com</Address>
<DeliveryOptions xmlns:p3="http://www.w3.org/2001/XMLSchema-instance" p3:type="DeliveryOptionsEmail">
<MailPriority>Normal</MailPriority>
</DeliveryOptions>
</DeliveryMechanism>
I need tag to be like
<Address>def#gmail.com,hij#gmail.com</Address>
This is not as simple as you might think...
The problem is: You should never ever store your data as a delimited string. Instead of the comma-separated list of email addresses, you should rather use a list of nested nodes. But sometimes we have to stick with bad design. This is a way to solve this:
A mockup-scenario with three test cases:
DECLARE #mockTable TABLE(ID INT IDENTITY, Descr VARCHAR(100), yourXml XML);
INSERT INTO #mockTable VALUES
('Your sample'
,'<DeliveryMechanism>
<ID>1</ID>
<Name>Email</Name>
<Description />
<IsActive>false</IsActive>
<Address>def#gmail.com,abc#gmail.com,hij#gmail.com</Address>
<DeliveryOptions xmlns:p3="http://www.w3.org/2001/XMLSchema-instance" p3:type="DeliveryOptionsEmail">
<MailPriority>Normal</MailPriority>
</DeliveryOptions>
</DeliveryMechanism>')
,('Your sample without the given mail address'
,'<DeliveryMechanism>
<ID>1</ID>
<Name>Email</Name>
<Description />
<IsActive>false</IsActive>
<Address>def#gmail.com,hij#gmail.com;oneMore#test.com</Address>
<DeliveryOptions xmlns:p3="http://www.w3.org/2001/XMLSchema-instance" p3:type="DeliveryOptionsEmail">
<MailPriority>Normal</MailPriority>
</DeliveryOptions>
</DeliveryMechanism>')
,('Your sample with twice the given mail address'
,'<DeliveryMechanism>
<ID>1</ID>
<Name>Email</Name>
<Description />
<IsActive>false</IsActive>
<Address>abc#gmail.com,hij#gmail.com,abc#gmail.com</Address>
<DeliveryOptions xmlns:p3="http://www.w3.org/2001/XMLSchema-instance" p3:type="DeliveryOptionsEmail">
<MailPriority>Normal</MailPriority>
</DeliveryOptions>
</DeliveryMechanism>');
--a variable to set the email we want to find and delete
DECLARE #givenAddress VARCHAR(100)='abc#gmail.com';
--the query
WITH PreComputation AS
(
SELECT t.*
,STUFF(
CAST('<x>' + REPLACE(t.yourXml.value('(/DeliveryMechanism/Address/text())[1]','nvarchar(max)'),',','</x><x>') + '</x>' AS XML)
.query('for $a in /x[text()[1] != sql:variable("#givenAddress")]/text()
return
<x>{concat(",",$a)}</x>').value('.','nvarchar(max)'),1,1,'') theNewList
FROM #mockTable t
WHERE t.yourXml.exist('/DeliveryMechanism[Address[contains(text()[1],sql:variable("#givenAddress"))]]')=1
)
UPDATE PreComputation SET yourXml.modify('replace value of (/DeliveryMechanism/Address/text())[1] with sql:column("theNewList")');
--Check the result
SELECT * FROM #mockTable;
The idea in short:
The CTE PreComputation will first use .exist() to reduce the work onto rows which contain the sepcific address.
The next step is to use some string manipulations, to transform your CSV-list to XML and cast it to a native XML.
Once having a native XML we can use XQuery
The .query() will return all email fragments, where the text() is not equal to the given address.
Some tricks with concat() ,.value() and STUFF() later, we now have the newly created CSV-list without the given address.
The final UPDATE can use this with sql:column().
Good luck ;-)
I can't figure out what I'm doing wrong. I have XML stored in a table column as text. I'm taking the ID, and the XML text and querying it into a temp table that stores the XML as XML type.
Each Order in the XML has multiple licenses in it that I need to pull out and create a new table with OrderID and License ID. But I can't tell what I'm doing wrong.
So, I'm trying to start basic but I can't seem to even just get the Account Info from the first Node.
The XML looks like this:
<ns1:OrderFromCRM xmlns:ns1="http://company.com/licensing/neworder/v2">
<ns1:AccountInfo Name="Company Name" AccountId="A012345" />
<ns1:OrderInfo CRMOrderId="S147360" Date="2/23/2017 12:00:00 AM" ffEmail="emailaddress.#gmail.com" >
<ns1:Licensing>
<ns1:Foundations>
<ns1:Foundation LicenseId="L012345678" Action="Create" Environment="Production" Type="Enterprise">
<Metadata>
<AllowedInstances>999</AllowedInstances>
</Metadata>
</ns1:Foundation>
<ns1:Foundation LicenseId="L012345698" Action="Create" Environment="Production" Type="Enterprise">
<Metadata>
<AllowedInstances>999</AllowedInstances>
</Metadata>
</ns1:Foundation>
</ns1:Foundations>
<ns1:Licenses Type="Create">
<ns1:License LicenseId="L0123451234" ProductFamily="Fam1" Product="EStudio" LicenseType="Perpetual" StartDate="2017-02-23" ExpiryDate="2017-12-18" MaintenanceExpiryDate="2017-12-18">
<ns1:Capabilities>
<ns1:Capability Name="T1" />
<ns1:Capability Name="Q1" />
<ns1:Capability Name="B1" />
</ns1:Capabilities>
</ns1:License>
<ns1:License LicenseId="L333356675" ProductFamily="Fam1" Product="EStudio" LicenseType="Perpetual" StartDate="2017-02-23" ExpiryDate="2017-12-18" MaintenanceExpiryDate="2017-12-18">
<ns1:Capabilities>
<ns1:Capability Name="T1" />
<ns1:Capability Name="Q1" />
<ns1:Capability Name="B1" />
</ns1:Capabilities>
</ns1:License>
The SQL I wrote is:
CREATE TABLE #demoData
(
ActivationCode NVARCHAR(100) NOT NULL,
OrderXMLText XML
)
SELECT OrderId, OrderXMLText.value('(/OrderFromCRM/AccountInfo)[1]', 'varchar(30)')
FROM #DEMODATA
I mentioned I need the OrderID and the LicenseId but even with this, I can't get anything. Am I on right track? First, what am I missing? Second, once this is formatted correctly, how do I get the nested LicenseIds in the XML?
Thanks so much for any help. I've been trying to make this work for a couple days
You’re missing the namespace so the query isn’t matching the xml, therefore it doesn’t find the elements you’re querying.
Add
;WITH XMLNAMESPACES
https://learn.microsoft.com/en-us/sql/t-sql/xml/with-xmlnamespaces
Assuming you have a complete, valid XML document in your table (the one you're showing is lacking several closing tags), then you could try something like this:
;WITH XMLNAMESPACES('http://company.com/licensing/neworder/v2' AS ns1)
SELECT
ActivationCode,
CRMOrderId = XC.value('#CRMOrderId', 'varchar(100)'),
FoundationsLicenseId = xcf.value('#LicenseId', 'varchar(50)'),
LicensesLicenseId = xcl.value('#LicenseId', 'varchar(50)')
FROM
#demoData
CROSS APPLY
OrderXMLText.nodes('/ns1:OrderFromCRM/ns1:OrderInfo') AS XT(XC)
CROSS APPLY
XC.nodes('ns1:Licensing/ns1:Foundations/ns1:Foundation') AS XTF(XCF)
CROSS APPLY
XC.nodes('ns1:Licensing/ns1:Licenses/ns1:License') AS XTL(XCL)
First of all, you need to include and respect the XML namespace in your XQuery - that's what I do with the WITH XMLNAMESPACES() directive.
Next, you need to use .nodes() to get a list of XML fragments for each <OrderInfo> node, which is located below the root node (<OrderFromCRM>). This is the first CROSS APPLY. This returns a list of XML fragments, one for each <OrderInfo> node.
Then you need to reach into these XML fragments, and again use CROSS APPLY with the .nodes() function to get a list of the <Foundation> elements (contained in the <Licensing>/<Foundations> subtree to get the license Id's from those nodes. In addition, you need a second CROSS APPLY to get all the <License> subnodes under <Licensing>/<Licenses> to get those LicenseId attributes.
That should return an output something like:
Hope this helps you some!
I have a Problem with saving the XML nodes in different Tables.
I want to save the Listnodes in one Table(ListsSet) and the Columnsnodes in another Table(ColumnsSet) which is referencing the ListTable. But in the Columnsnode is also a DependentLookupField childnode. I want to save the value from the DependentLookupField in a third Table(DependentLookupFieldsSet), which is referencing the ColumnTable.
My XML:
<Lists>
<List title="test">
<ListUrl>fsasa</ListUrl>
<ListTitle>gsdfgsg</ListTitle>
<ListDesc>jasdh</ListDesc>
<Columns>
<Column action="modify">
<InternalName>Title</InternalName>
<DisplayNameOrigin>Titel</DisplayNameOrigin>
<DisplayName>Name</DisplayName>
</Column>
<Column action="new">
<Required>true</Required>
<FieldType>Choice</FieldType>
<InternalName>anrede</InternalName>
<DisplayName>Anrede</DisplayName>
</Column>
<Column action="add" type="sitecolumn">
<Required>true</Required>
<InternalName>Bank</InternalName>
<DisplayName>Bank</DisplayName>
<MultipleValues>0</MultipleValues>
<DependentLookupFields>
<DependentLookupField internalName="Title">My Value</DependentLookupField>
</DependentLookupFields>
</Column>
</Columns>
</List>
<List>
.
.
.
etc
</List>
</Lists>
My Code of the Stored Procedure:
INSERT INTO ListsSet
SELECT
List.value('ListUrl[1]','NVARCHAR(100)') AS ListURL,
List.value('ListTitle[1]','NVARCHAR(100)') AS ListTitle,
List.value('ListDesc[1]','NVARCHAR(100)') AS ListDesc,
FROM
#xml.nodes('/Lists/List')AS TEMPTABLE(List)
INSERT INTO ColumnsSet
SELECT
l.ListsID,
c.value('FieldType[1]','NVARCHAR(100)') AS FieldType,
c.value('InternalName[1]','NVARCHAR(100)') AS InternalName,
c.value('DisplayName[1]','NVARCHAR(100)') AS DisplayName,
c.value('Required[1]','NVARCHAR(100)') AS Required,
c.value('DisplayNameOrigin[1]','NVARCHAR(100)') AS DisplayNameOrigin,
c.value('MultipleValues[1]','NVARCHAR(100)') AS MultipleValues,
FROM
ListsSet AS l
cross apply #xml.nodes('/Lists/List/Columns/Column[../../ListUrl=sql:column("l.ListUrl")]') AS TEMPTABLE(c)
INSERT INTO DependentLookupFieldsSet
SELECT
c.ColumnsID,
d.value('DependentLookupField[1]','NVARCHAR(100)') AS DependetLookupField
FROM
ColumnsSet AS c
cross apply #xml.nodes('/Lists/List/Columns/Column/DependentLookupFields/DependentLookupField[../../InternalName=sql:column("c.InternalName")]') AS TEMPTABLE(d)
The Code for saving the Listsnodes and Columnsnode is working fine. But the Code for the DependentLookupField don't save the value. In the Table "DependentLookupFieldsSet" I get the Rows which are referencing the ColumsTable(that is working), but the saved value is always null in each row.
Any help is appreciated!
I need to export data from SQL Server 2012 based on a view. While testing the export for a downstream system, I was manually extracting the data out of the table that the view is based on and the BIT data type columns were reporting as 1/0.
However, once I setup the view against the table, I noticed that the BIT data type columns reported as TRUE/FALSE. This happens whether I perform a select against the view or export from it.
Why does this happen and how can I maintain the same results in the view as the data table (1/0)?
The bit data type is interpreted by clients differently. SSMS, will report back a 1 or 0 for a bit while the same 1/0 is interpreted by an SSIS's Data Flow as True or False.
Whether the source is a table or a view makes no matter for SSIS unless you explicitly change the data type.
For setup, I created 2 tables and a view
CREATE TABLE dbo.BaseTable
(
SomeBit bit NOT NULL
, RowDescription varchar(50) NOT NULL
);
CREATE TABLE dbo.TargetTable
(
SomeBit bit NOT NULL
, RowDescription varchar(50) NOT NULL
, SourcePackage nvarchar(100) NOT NULL
);
GO
CREATE VIEW dbo.MyView
AS
SELECT
BT.SomeBit
, BT.RowDescription
FROM
dbo.BaseTable AS BT;
GO
INSERT INTO
dbo.BaseTable
(
SomeBit
, RowDescription
)
VALUES
(CAST(0 AS bit), 'Falsification')
, (CAST(1 AS bit), 'True dat');
GO
At this point, if I use SSMS and query either dbo.BaseTable or dbo.MyView, I will get back a 1 and 0. But again, these are just artifacts of presentation. In C, 0 is false and any numeric value that isn't 0 is true. Excel will present it as FALSE and TRUE. Every client will interpret the value into whatever the local representation of a boolean value is. SSIS chose True and False.
I built out a simple package that pulls data from BaseTable or MyView and writes it to a text file and a table.
The basic control flow looks thus
The data flow looks complex but it's not.
I select from either my table or view, add a description for my target table, use a multicast so I can send the same data to multiple destinations and then write to a file and table.
If I query SSMS for my sources and destinations, you'll see that the destination libraries handle the translation between the local and foreign representation of the data type.
There is no such translation available for a flat file because there's no "standard" for the representation of a boolean. I might like Y/N. Even so, the
I tried a number of things to coerce a 1/0 to be written to the flat file. I set my data types to
Boolean DT_BOOL
Single byte signed int DT_I1
Four byte signed int DT_I4
String DT_STR
but it never mattered (which actually seems odd given how persnickety SSIS is about data types) --- my output was always the same
False,Falsification
True,True dat
Ultimately, if I wanted a 0 or a 1 in that output file, I needed to change my data type: either in the source query with an explicit cast or through a Derived Column component using the ternary operator SomeBit ? (DT_I1)1 : (DT_I1)0. Use DT_I1/I2/I4/I8 as you see fit
Fun trivia note: if you chose to use the Data Conversion component you're going to get 0 for False, -1 for True or if you use a lazy cast in the Derived Component (DT_I1) SomeBit It seems they follow the C interpretation of boolean values.
Biml it
No need to take my word for it. Using the above table definitions and population of values, if you install the free addon BIDS Helper you can generate the same code for any version of SSIS.
After installing BIDS Helper, right click on an SSIS project and in the context menu, select Add Biml file. Replace the contents of that file with the below code; save and then right-click to generate a new package.
You will need to edit the values for the Flat File Connection to point to valid locations as well as point the ole db connection string to wherever you spin up your tables.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<FlatFileConnection FilePath="C:\ssisdata\so_29244868.table.csv" FileFormat="FFF_table" Name="FF_Table" />
<FlatFileConnection FilePath="C:\ssisdata\so_29244868.view.csv" FileFormat="FFF_table" Name="FF_View" />
<OleDbConnection Name="CM_OLE" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI11.0;Integrated Security=SSPI;" />
</Connections>
<FileFormats>
<FlatFileFormat
Name="FFF_table" IsUnicode="false" CodePage="1252"
FlatFileType="RaggedRight">
<Columns>
<Column Name="SomeBit" DataType="Boolean" Delimiter="," />
<Column Name="RowDescription" DataType="AnsiString" Length="50" Delimiter="CRLF"/>
</Columns>
</FlatFileFormat>
</FileFormats>
<Packages>
<Package ConstraintMode="Parallel" Name="so_29244868">
<Tasks>
<Dataflow Name="DFT Table example">
<Transformations>
<OleDbSource ConnectionName="CM_OLE" Name="OLE_SRC dbo_BaseTable">
<ExternalTableInput Table="dbo.BaseTable" />
</OleDbSource>
<DerivedColumns Name="DER Package name">
<Columns>
<Column DataType="String" Name="SourcePackage" Length="100">"DFT Table example"</Column>
</Columns>
</DerivedColumns>
<Multicast Name="MC Dupe">
<OutputPaths>
<OutputPath Name="FF" />
<OutputPath Name="Table" />
</OutputPaths>
</Multicast>
<FlatFileDestination ConnectionName="FF_Table" Name="FF_DST table">
<InputPath OutputPathName="MC Dupe.FF" />
</FlatFileDestination>
<OleDbDestination
ConnectionName="CM_OLE"
Name="OLE_DST Table"
TableLock="false">
<InputPath OutputPathName="MC Dupe.Table" />
<ExternalTableOutput Table="[dbo].[TargetTable]"></ExternalTableOutput>
</OleDbDestination>
</Transformations>
</Dataflow>
<Dataflow Name="DFT View example">
<Transformations>
<OleDbSource ConnectionName="CM_OLE" Name="OLE_SRC dbo_MyView">
<ExternalTableInput Table="dbo.MyView" />
</OleDbSource>
<DerivedColumns Name="DER Package name">
<Columns>
<Column DataType="String" Name="SourcePackage" Length="100">"DFT View example"</Column>
</Columns>
</DerivedColumns>
<Multicast Name="MC Dupe">
<OutputPaths>
<OutputPath Name="FF" />
<OutputPath Name="Table" />
</OutputPaths>
</Multicast>
<FlatFileDestination ConnectionName="FF_View" Name="FF_DST view">
<InputPath OutputPathName="MC Dupe.FF" />
</FlatFileDestination>
<OleDbDestination
ConnectionName="CM_OLE"
Name="OLE_DST view"
TableLock="false"
>
<InputPath OutputPathName="MC Dupe.Table" />
<ExternalTableOutput Table="[dbo].[TargetTable]"></ExternalTableOutput>
</OleDbDestination>
</Transformations>
</Dataflow>
</Tasks>
</Package>
</Packages>
</Biml>
I've run into the same problem using Entity Framework.
Try casting the bit field to a bit.
I need to get some information from XML in SQL Server 2008, but I cannot even get basic attribute from it. All samples that I tried failed. Table name is Item, xml column name is Data.
Simplified xml looks like this:
<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 Signature="a3502dd0-8c16-4023-9eea-30ea1c7a3a2b">
<Topology xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008">
<Services>
<Service RoleVersion="1" ServiceVersion="6" Type="Microsoft.Rtc.Management.Deploy.Internal.ServiceRoles.FileStoreService">
<ServiceId SiteId="1" RoleName="FileStore" Instance="1" />
<DependsOn />
<InstalledOn>
<ClusterId SiteId="1" Number="1" />
</InstalledOn>
<Ports xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008" />
<FileStoreService xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008" ShareName="lyncShare" />
</Service>
</Services>
</Topology>
</Value>
</Item>
</Dictionary>
</AnchoredXml>
I need to read information in AnchoredXml/Key/SchemaId/#NameSpace to select the right xml (there are more rows). Sample xml above is the right one. And after that I need to find the right service with
Type="Microsoft.Rtc.Management.Deploy.Internal.ServiceRoles.FileStoreService"
where is FileStoreService/#ShareName that I need.
I've tried to print the Namespace attributte for the start, but no sample code is working.
A few tries:
SELECT c.p.value('(#Namespace)[1]', 'varchar(50)') as 'Nmspace'
FROM Item
CROSS APPLY Data.nodes('/AnchoredXml/Key/SchemaId') c(p)
returns empty result set
SELECT Data.value('(/AnchoredXml/Key/SchemaId/#Namespace)[1]', 'varchar(50)')
FROM Item
returns NULL for all rows
SELECT
It.Data.exist('/AnchoredXml/Key/SchemaId[#Namespace="Microsoft.Rtc.Management.Deploy.Topology.2008"]')
FROM [xds].[dbo].[Item] AS It
returns 0's for all rows also without quotes ("")
A working sample code to get at least attribute test would be maybe sufficient and I would figure out the rest.
Could you please help me find errors in my queries or maybe identify some other problem?
Thanks
You're ignoring all the XML namespaces in your XML document! You need to pay attention to those and respect them!
There are XML namespaces on:
the root node <AnchoredXml>
(XML namespace: urn:schema:Microsoft.Rtc.Management.ScopeFramework.2008)
the subnode <Topology>
(XML ns: urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008)
the subnode <FileStoreService>
(XML ns: urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008)
Try this:
-- respect the XML namespaces!!
;WITH XMLNAMESPACES(DEFAULT 'urn:schema:Microsoft.Rtc.Management.ScopeFramework.2008',
'urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008' AS t,
'urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008' AS fss)
SELECT
ShareName = Data.value('(/AnchoredXml/Dictionary/Item/Value/t:Topology/t:Services/t:Service/fss:FileStoreService/#ShareName)[1]', 'varchar(50)')
FROM
dbo.Item
In my case, this returns:
ShareName
-----------
lyncShare