How do I add a node or new element in SQL Server using XQuery and the xml datatype?

You can achieve this with code something like this.

You can achieve this with code something like this: -- declare a table variable to hold the data DECLARE @table TABLE (ID INT IDENTITY PRIMARY KEY, XmlContent XML) -- insert your XML into that table variable INSERT INTO @table(XmlContent) VALUES(@Settingsxml) -- define the relevant XML namespaces and UPDATE the table ;WITH XMLNAMESPACES('http://schemas.microsoft.com/winfx/2006/xaml/presentation' AS ns, 'clr-namespace:System;assembly=mscorlib' AS sys, 'http://schemas.microsoft.com/winfx/2006/xaml' as x) UPDATE @table SET XmlContent. Modify('insert 300 after (/ns:ResourceDictionary/sys:Int32@x:Key="abc")1') WHERE ID = 1 -- now, your XML stored in the table variable contains the new element where you wanted to have it SELECT XmlContent FROM @table The output in the end is: 1200 300 300 300 Forgot your login or password? Please contact the IT Dept.

Same answer as given by marc_s but using set on XML variable instead of update on table variable. Can't use with xmlnamespaces here so ... set @Settingsxml. Modify('declare default element namespace "schemas.microsoft.com/winfx/2006/xaml/pr...; declare namespace x="schemas.microsoft.com/winfx/2006/xaml"; declare namespace sys="clr-namespace:System;assembly=mscorlib"; insert 300 after (/ResourceDictionary/sys:Int32@x:Key="abc")1').

Interesting.... I kept trying to do it this way, but I used SELECT @settingsxml. Modify(....) and kept having errors..... why didn't I think of SET instead!?!?!? :-) – marc_s 12 hours ago @marc_s - I knew SET would work but I had to struggle a bit with the syntax for the namespaces.

Relly wanted to use a default namespace.It was too late last night but I figured it out now. – Mikael Eriksson 10 hours ago.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions