SQL check XML node exists via a variable, add & delete -


I'm exploring a way to check whether NODE exists in an XML data type using any MODQL 2012 I want to see the varchar in a stored procedure as node, I have tried something like the bottom, but it does not appear to work, what I want to do is "null" Var2 (SP) As passed in varchar), and if it exists, So if it does not exist, then insert it into the root of all the nodes found in all the examples are hardcodes, which works.

Code as a variable with node:

  declared @node varchar (255) declared @ x xml set @ annode = 'var2' set @ x = ' & Lt; Root & gt; & Lt; Var1 & gt; 0 & lt; / Var1 & gt; & Lt; Var2 & gt; 123 & lt; / Var2 & gt; & Lt; var3 & gt; 1000 & lt; / Var3 & gt; & Lt; var4 & gt; 989 & lt; / var4 & gt; & Lt; / Root & gt; 'Code with hardcod node: @ x.exist (' //. [Node (=) (select "variable: variable (" node ")] '' - always gives false returns   < P>  
  select @ x.exist ('// var2') - returns true   

If the node is present, then back into the root element node

Edit:

I have done the work I can do the following:

  select @ x.exist ('// * [local-name () = sql: variable ("node") ') - 1 when node exists   

If the node does not exist, then I add a new node this way Can be set to:

  set @add = '& lt; newNode & gt; test & lt; / newNode & gt;' @ X.modify ('enter sql: variable ("@ add" ) I can remove the existing nodes in this way:  
  set @del = 'newNode' (/ root) [1] ')   

Can not be removed to work on @x.modify ('delete / root / * [local-name () = sql: variable ("@ del")])

.

I have done my answer to my question:

  - Check to see if NODE exists @ node varchar (255) set @node = "existingnode" @x.exist ('// * [local-name] = sql: variable ("@ node")]') - Add a new node: Announce @add as xml set @add = '& lt; Abc & gt; Testing & lt; / Abc & gt; '@ X.modify (') in sql: variable ("@ add") (/ root) [1] ') - To delete a node: @ DL, declare it as varchar (255) @ del = 'abc' @x .modify ('delete / root / * [local-name () = sql: variable ("@ del")]')   

The reason for my question and answer It is that I wanted to work on node names, not attribute values.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -