Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t修改XML节点';T-SQL中的s值(ms SQL)_Xml_Tsql_Xml Dml - Fatal编程技术网

Can';t修改XML节点';T-SQL中的s值(ms SQL)

Can';t修改XML节点';T-SQL中的s值(ms SQL),xml,tsql,xml-dml,Xml,Tsql,Xml Dml,我想在mssql中修改xml的节点值,但我的方法似乎不起作用 这是一个xml示例: <xml> <ProjectManager> <People> <DisplayNames>John Smith</DisplayNames> <LoginNames>ABC\jsmith</LoginNames> </People> </ProjectManage

我想在mssql中修改xml的节点值,但我的方法似乎不起作用

这是一个xml示例:

<xml>
  <ProjectManager>
    <People>
      <DisplayNames>John Smith</DisplayNames>
      <LoginNames>ABC\jsmith</LoginNames>
    </People>
  </ProjectManager>
</xml>
CREATE FUNCTION [dbo].[MyFunc](
    @properties xml, 
    @key nvarchar(50),
    @newvalue nvarchar(max), 
    @datatype nvarchar(50) = null,
    @node nvarchar(50) = null) 
    RETURNS xml
WITH SCHEMABINDING
AS BEGIN 
    DECLARE @temp XML = @properties

    IF LOWER(@datatype) = 'people' 
        SET @temp.modify('replace value of (/xml/*[local-name() = sql:variable("@key")][1]/People/*[local-name() = sql:variable("@node")]/text())[1] with sql:variable("@newvalue")')

RETURN @temp;
END
set @result = dbo.MyFunc(@myXML,'ProjectManager','Somebody','People','DisplayName')
调用函数:

<xml>
  <ProjectManager>
    <People>
      <DisplayNames>John Smith</DisplayNames>
      <LoginNames>ABC\jsmith</LoginNames>
    </People>
  </ProjectManager>
</xml>
CREATE FUNCTION [dbo].[MyFunc](
    @properties xml, 
    @key nvarchar(50),
    @newvalue nvarchar(max), 
    @datatype nvarchar(50) = null,
    @node nvarchar(50) = null) 
    RETURNS xml
WITH SCHEMABINDING
AS BEGIN 
    DECLARE @temp XML = @properties

    IF LOWER(@datatype) = 'people' 
        SET @temp.modify('replace value of (/xml/*[local-name() = sql:variable("@key")][1]/People/*[local-name() = sql:variable("@node")]/text())[1] with sql:variable("@newvalue")')

RETURN @temp;
END
set @result = dbo.MyFunc(@myXML,'ProjectManager','Somebody','People','DisplayName')

DisplayName在XML中是复数形式

使用