Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
Sql server 使用TSQL将所有值从XML字符串中分条(SQL SERVER 2008)_Sql Server_Sql Server 2008_Tsql - Fatal编程技术网

Sql server 使用TSQL将所有值从XML字符串中分条(SQL SERVER 2008)

Sql server 使用TSQL将所有值从XML字符串中分条(SQL SERVER 2008),sql-server,sql-server-2008,tsql,Sql Server,Sql Server 2008,Tsql,我正在研究一个问题,需要将给定的XML与没有值的用户输入进行比较,例如,如果这是用户输入: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <genRetrieve xmlns:v1="http://xxxxxxxxxxxxxxxxxxxxx">

我正在研究一个问题,需要将给定的XML与没有值的用户输入进行比较,例如,如果这是用户输入:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <genRetrieve xmlns:v1="http://xxxxxxxxxxxxxxxxxxxxx">
                <checkRetrieve>
                    <party>
                        <user>
                            <first>BLA</first>
                            <last>last</last>
                        </user>
                        <media>none</media>
                    </party>
                </checkRetrieve>
            </genRetrieve>
        </soapenv:Body>
    </soapenv:Envelope> 

但是,使用上述命令的表的输出构建最终的XML字符串似乎很棘手,如果您能告诉我标准/最有效的方法(考虑到XML字符串中包含许多元素),我将不胜感激。

您可以使用XML数据类型并使用删除所有
text()
节点

declare@xml=
'
布拉
最后的
没有一个
'
set@xml.modify('delete/*/text()'))
选择@xml
结果:


您确定为作业选择了正确的工具吗?我确信在发送数据的数据库代码之上有某种东西,它可能是一种比T-SQL功能更全面的语言,并且可以访问更常规的XML处理库。
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <genRetrieve xmlns:v1="http://xxxxxxxxxxxxxxxxxxxxx">
                <checkRetrieve>
                    <party>
                        <user>
                            <first></first>
                            <last></last>
                        </user>
                        <media></media>
                    </party>
                </checkRetrieve>
            </genRetrieve>
        </soapenv:Body>
    </soapenv:Envelope>
    DECLARE @hdoc     int
    DECLARE @doc      varchar(2000)

    SET @doc = 'my xml'

    EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc

    SELECT * FROM OPENXML( @hdoc, '/*',2)

    EXEC sp_xml_removedocument @hdoc
    GO