Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.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 对于那些具有datasourceName子节点且其值等于my sql变量的XML和返回name属性,然后返回服务器或用户节点的name值。xml中可以有多个服务器和用户节点。我还没有找到使用xquery实现这一点的方法,所以我可能不得不考虑采用另一种方法。_Sql Server_Xml_Tsql_Xpath_Xquery - Fatal编程技术网

Sql server 对于那些具有datasourceName子节点且其值等于my sql变量的XML和返回name属性,然后返回服务器或用户节点的name值。xml中可以有多个服务器和用户节点。我还没有找到使用xquery实现这一点的方法,所以我可能不得不考虑采用另一种方法。

Sql server 对于那些具有datasourceName子节点且其值等于my sql变量的XML和返回name属性,然后返回服务器或用户节点的name值。xml中可以有多个服务器和用户节点。我还没有找到使用xquery实现这一点的方法,所以我可能不得不考虑采用另一种方法。,sql-server,xml,tsql,xpath,xquery,Sql Server,Xml,Tsql,Xpath,Xquery,对于那些具有datasourceName子节点且其值等于my sql变量的XML和返回name属性,然后返回服务器或用户节点的name值。xml中可以有多个服务器和用户节点。我还没有找到使用xquery实现这一点的方法,所以我可能不得不考虑采用另一种方法。@Fillister,你检查过我的答案了吗?我想这正是你需要的。。。加上“投票”:你可以做两件事:每一件贡献都是好的或坏的。你应该非常慷慨地行使你的投票权,无论你走到哪里。找到一个好答案?伟大的投票吧!找到什么愚蠢的东西?投票吧!此外,作为提问


对于那些具有datasourceName子节点且其值等于my sql变量的XML和返回name属性,然后返回服务器或用户节点的name值。xml中可以有多个服务器和用户节点。我还没有找到使用xquery实现这一点的方法,所以我可能不得不考虑采用另一种方法。@Fillister,你检查过我的答案了吗?我想这正是你需要的。。。加上“投票”:你可以做两件事:每一件贡献都是好的或坏的。你应该非常慷慨地行使你的投票权,无论你走到哪里。找到一个好答案?伟大的投票吧!找到什么愚蠢的东西?投票吧!此外,作为提问者,你有权接受最佳答案(投票柜台下方的支票)。这标志着一个问题已经解决。我不确定我是否明白你的意思。我从数据类型为varchar(max)的表列中提取xml数据,并将其放入xml数据类型的变量中。如果这有什么不同的话,那就是SQL Server 2008R2。嗨@Fillister,我不知道你到底在做什么。。。在我的示例中,我用一个varchar列和两个不同的XML填充了一个测试表。select将读取此列,在
交叉应用中动态转换为XML,然后使用
.exist()
作为筛选器。您也可以使用
.nodes()
和其他XML方法。因此:1)是否需要使用声明的XML变量?2) 您是只处理一个XML还是一次处理多个XML?如果只使用自己的方法,但使用
sql:variable()
将值放入
XPath
,会发生什么情况?该列命名为XML,并设置为varchar(max)数据类型。本专栏中只有关于XML的文章,需要记住的一点是,我擅长SQL,但对XQuery不熟悉。该列名为XML,并设置为varchar(max)数据类型。在该列中只有关于XML的内容。目标是从该列中获取xml数据,并在存在名为Source的子标记时找到用户标记的name属性,该子标记的值与我的sql变量匹配。恐怕我不知道XQuery或XML足以使用正确的术语。@ FLILSTER,你应该考虑改变数据类型,而不是让它成为代码> VARCHAR(MAX)我使用SQL Server 2008 R2。但是如果我使用你的方法或者Shnugo提供的方法,我会得到一个空值。@Fillister所以你复制粘贴了我发布的摘录,你得到了空值?或者您将它与另一个XML一起使用?我对它进行了修改,以便与我刚刚发布的示例一起使用,但我弄错了。它没有任何回报。如果你愿意的话,我可以把我修改过的东西贴上去?
   <business_process>
<ProcessDefinition name="dawns test">
    <StartState name="START" uniqueId="Node3304">
        <Transition name="Node4532" to="Node4532"/>
    </StartState>
    <EndState name="END4694" uniqueId="Node4694"/>
    <User name="Node4532" uniqueId="Node4532">
        <Description>test</Description>
        <Distribution config-type="field" type="CommonQueueDistribution">
            <Priority>0</Priority>
            <AutoCompleteJob>false</AutoCompleteJob>
            <GroupId>Admin</GroupId>
            <UseAttendance>false</UseAttendance>
            <UseShifts>false</UseShifts>
            <NotifyActors>false</NotifyActors>
        </Distribution>
        <DocFinityTask type="DocFinityTask">
            <description>read e-mail and approve or deny</description>
            <help/>
            <required>false</required>
            <redoable>false</redoable>
            <condition/>
            <properties>
                <undoable>true</undoable>
            </properties>
        </DocFinityTask>
        <DocFinityTask type="SimpleFormTask">
            <description>lob lookup</description>
            <help/>
            <required>false</required>
            <redoable>true</redoable>
            <condition/>
            <properties>
                <autoRun>true</autoRun>
                <form>
                    <title>lob</title>
                    <formElement>
                        <type>Combobox</type>
                        <variable>lob</variable>
                        <tooltip>lob lookup</tooltip>
                        <label>lob</label>
                        <required>false</required>
                        <prepopulateValues>
                            <datasourceName>lob lookup</datasourceName>
                        </prepopulateValues>
                        <userEnter>true</userEnter>
                        <dataType>STRING</dataType>
                    </formElement>
                </form>
            </properties>
        </DocFinityTask>
        <Transition name="Node128795" to="Node128795"/>
    </User>
    <Server name="Node128795" uniqueId="Node128795">
        <Description/>
        <Event type="node-enter">
            <Action type="SetProcessInstancePropertyAction" config-type="field">
                <description>Whatever</description>
                <propertyName>source</propertyName>
                <datasourceName>get datasource list</datasourceName>
            </Action>
        </Event>
        <Transition name="Node4694" to="END4694"/>
    </Server>
    <Server name="Node250" uniqueId="Node250">
      <Description />
      <Event type="node-enter">
        <Action type="SetProcessInstancePropertyAction" config-type="field">
          <description>Whatever</description>
          <propertyName>source</propertyName>
          <datasourceName>stump</datasourceName>
        </Action>
      </Event>
      <Transition name="Node4694" to="END4694" />
    </Server>
</ProcessDefinition>
<Layout>
    <annotations/>
    <nodes>
        <node name="START" uniqueId="Node3304" type="startNode" text="START" x="184.5" y="135.5" width="25" height="25"/>
        <node name="END4694" uniqueId="Node4694" type="endNode" text="END4694" x="588.5" y="137.5" width="25" height="25"/>
        <node name="Node4532" uniqueId="Node4532" type="userNode" text="Node4532" info="false" x="296" y="135" width="150" height="50"/>
        <node name="Node128795" uniqueId="Node128795" type="serverNode" text="Node128795" info="false" x="286" y="244" width="150" height="50"/>
    </nodes>
    <edges>
        <edge originNode="Node3304" targetNode="Node4532" text="" sketch="arrow"/>
        <edge originNode="Node4532" targetNode="Node128795" text="" sketch="arrow"/>
        <edge originNode="Node128795" targetNode="Node4694" text="" sketch="arrow"/>
    </edges>
</Layout>
DECLARE @xml XML=
            (SELECT [XML] 
             FROM ProcessModels 
             WHERE [XML] LIKE '%<datasourceName>' + @dsName + '%' 
                    and [status] = 'ACTIVE')
select sn.value('@name', 'varchar(100)') AS ServerNodes
from @xml.nodes('/business_process/ProcessDefinition/Server')  AS ServerNodes(sn)
SELECT ServerNode.value('@name','varchar(max)') AS ServerNode
FROM @xml.nodes('/business_process/ProcessDefinition') AS ProcessDefinition(pd)
OUTER APPLY pd.nodes('Server[Event//datasourceName=sql:variable("@searchVariable")]') AS The(ServerNode)
WHERE ServerNode.value('@name','varchar(max)') IS NOT NULL

SELECT UserNode.value('@name','varchar(max)') AS UserNode
FROM @xml.nodes('/business_process/ProcessDefinition') AS ProcessDefinition(pd)
OUTER APPLY pd.nodes('User[DocFinityTask//datasourceName=sql:variable("@searchVariable")]') AS The(UserNode)
WHERE UserNode.value('@name','varchar(max)') IS NOT NULL
DECLARE @tbl TABLE(ID INT IDENTITY, YourXMLAsVarchar VARCHAR(MAX));
INSERT INTO @tbl VALUES 
('<User name="First Node" uniqueId="1332">
    <Task type="Form">
      <properties>
        <form>
          <formElement>
            <populateValues>
              <source>lookup</source>
            </populateValues>
          </formElement>
        </form>
      </properties>
    </Task>
   </User>')
,('<User name="First Node" uniqueId="1332">
    <Task type="Form">
      <properties>
        <form>
          <formElement>
            <populateValues>
              <source>another</source>
            </populateValues>
          </formElement>
        </form>
      </properties>
    </Task>
   </User>');


--Search for "lookup"
DECLARE @SearchingFor VARCHAR(100)='lookup';

--Search with full path
SELECT x.value('(/User/@name)[1]','varchar(max)')
FROM @tbl AS tbl
CROSS APPLY(SELECT CAST(YourXMLAsVarchar AS XML)) AS a(x)
WHERE x.exist('/User/Task/properties/form/formElement/populateValues/source[.=sql:variable("@SearchingFor")]')=1

--shorter, if there is not other "source" element this could be muddled up with...
SELECT x.value('(/User/@name)[1]','varchar(max)')
FROM @tbl AS tbl
CROSS APPLY(SELECT CAST(YourXMLAsVarchar AS XML)) AS a(x)
WHERE x.exist('//source[.=sql:variable("@SearchingFor")]')=1

--even shorter, if your lookup string won't be anywhere else an element's value
SELECT x.value('(/User/@name)[1]','varchar(max)')
FROM @tbl AS tbl
CROSS APPLY(SELECT CAST(YourXMLAsVarchar AS XML)) AS a(x)
WHERE x.exist('//*[.=sql:variable("@SearchingFor")]')=1
DECLARE @xml XML=
'<User name="First Node" uniqueId="1332">
    <Task type="Form">
        <properties>
            <form>
                <formElement>
                    <populateValues>
                        <source>lookup</source>
                    </populateValues>
                </formElement>
            </form>
        </properties>
    </Task>
</User>';

DECLARE @lookup NVARCHAR(128)='lookup';

SELECT
    n.v.value('../../../../../../@name','NVARCHAR(128)') AS name
FROM
    @xml.nodes('//User/Task/properties/form/formElement/populateValues/source[.=sql:variable("@lookup")]') AS n(v);
DECLARE @xml XML=
'<business_process>
  <ProcessDefinition name="dawns test">
    <StartState name="START" uniqueId="Node3304">
      <Transition name="Node4532" to="Node4532" />
    </StartState>
    <EndState name="END4694" uniqueId="Node4694" />
    <User name="Node4532" uniqueId="Node4532">
      <Description>test</Description>
      <Distribution config-type="field" type="CommonQueueDistribution">
        <Priority>0</Priority>
        <AutoCompleteJob>false</AutoCompleteJob>
        <GroupId>Admin</GroupId>
        <UseAttendance>false</UseAttendance>
        <UseShifts>false</UseShifts>
        <NotifyActors>false</NotifyActors>
      </Distribution>
      <DocFinityTask type="DocFinityTask">
        <description>read e-mail and approve or deny</description>
        <help />
        <required>false</required>
        <redoable>false</redoable>
        <condition />
        <properties>
          <undoable>true</undoable>
        </properties>
      </DocFinityTask>
      <DocFinityTask type="SimpleFormTask">
        <description>lob lookup</description>
        <help />
        <required>false</required>
        <redoable>true</redoable>
        <condition />
        <properties>
          <autoRun>true</autoRun>
          <form>
            <title>lob</title>
            <formElement>
              <type>Combobox</type>
              <variable>lob</variable>
              <tooltip>lob lookup</tooltip>
              <label>lob</label>
              <required>false</required>
              <prepopulateValues>
                <datasourceName>lob lookup</datasourceName>
              </prepopulateValues>
              <userEnter>true</userEnter>
              <dataType>STRING</dataType>
            </formElement>
          </form>
        </properties>
      </DocFinityTask>
      <Transition name="Node128795" to="Node128795" />
    </User>
    <Server name="Node128795" uniqueId="Node128795">
      <Description />
      <Event type="node-enter">
        <Action type="SetProcessInstancePropertyAction" config-type="field">
          <description>Whatever</description>
          <propertyName>source</propertyName>
          <datasourceName>get datasource list</datasourceName>
        </Action>
      </Event>
      <Transition name="Node4694" to="END4694" />
    </Server>
  </ProcessDefinition>
  <Layout>
    <annotations />
    <nodes>
      <node name="START" uniqueId="Node3304" type="startNode" text="START" x="184.5" y="135.5" width="25" height="25" />
      <node name="END4694" uniqueId="Node4694" type="endNode" text="END4694" x="588.5" y="137.5" width="25" height="25" />
      <node name="Node4532" uniqueId="Node4532" type="userNode" text="Node4532" info="false" x="296" y="135" width="150" height="50" />
      <node name="Node128795" uniqueId="Node128795" type="serverNode" text="Node128795" info="false" x="286" y="244" width="150" height="50" />
    </nodes>
    <edges>
      <edge originNode="Node3304" targetNode="Node4532" text="" sketch="arrow" />
      <edge originNode="Node4532" targetNode="Node128795" text="" sketch="arrow" />
      <edge originNode="Node128795" targetNode="Node4694" text="" sketch="arrow" />
    </edges>
  </Layout>
</business_process>';

DECLARE @searchVariable VARCHAR(100)='get datasource list';

SELECT ServerNode.value('@name','varchar(max)') AS ServerName
      ,ServerNode.value('@uniqueId','varchar(max)') AS ServerId
      ,pd.value('User[1]/@name','varchar(max)') AS UserName
      ,pd.value('User[1]/@uniqueId','varchar(max)') AS UserId
FROM @xml.nodes('/business_process/ProcessDefinition') AS ProcessDefinition(pd)
OUTER APPLY pd.nodes('Server[Event/Action/datasourceName=sql:variable("@searchVariable")]') AS The(ServerNode);