0

我有一个 xml 格式的消息列表,我想使用 OpenXML 将消息 ID 发送到存储过程,将它们的状态更新为“A”状态。您可以在此处查看编码,如下所示:

XML 样本格式:

 <Message>
    <MessageID>17</MessageID>
    <MessageID>16</MessageID>
    <MessageID>15</MessageID>
 </Message>

在存储过程中:

exec sp_xml_preparedocument @idoc OUTPUT, @XmlMessagesItems  

方式一:

UPDATE SECMSG_TO   
SET SECMSG_TO.Status='A'
FROM OPENXML (@idoc, '/Message',2) 
     with ( MessageID INT) ox  
WHERE  
    SECMSG_TO.MessageID = ox.MessageID 

或方式2:

  UPDATE SECMSG_TO   
  SET SECMSG_TO.Status = 'A'
  WHERE SECMSG_TO.MessageID IN (SELECT *  
                                FROM OPENXML  (@idoc, '/Message',2) 
                                WITH ( MessageID INT)        
                            )

但是通过这两种方式,我只能更新第一条消息,这意味着 17 号和其他没有影响。你能给我一个线索,我怎样才能完全更新所有列表。

谢谢。

4

4 回答 4

0
 XML Format
  <?xml version="1.0" encoding="utf-8" ?>
  <Messages>
    <Message MessageID='33' />
    <Message MessageID='34' />
    <Message MessageID='20' />   
  </Messages>

    in Stored Procedure
    SELECT @MessageID = MessageID      
    FROM OPENXML (@idoc, '/Messages/Message', 1)             
     WITH       
     (             
         MessageID   int 
     )        

     UPDATE TableName SET Status='A'     
         WHERE MessageID = @MessageID 
于 2012-05-31T23:00:25.643 回答
0
First Way: XML Format
  <?xml version="1.0" encoding="utf-8" ?>
  <Messages>
    <Message MessageID='33' />
    <Message MessageID='34' />
    <Message MessageID='20' />   
  </Messages>

 in Stored Procedure
  @XmlMessagesItems text
  DECLARE @idoc INT
  EXEC sp_xml_preparedocument @idoc OUTPUT, @XmlMessagesItems  
  UPDATE TableName   SET Status='A'
              from OPENXML  (@idoc, '/Messages/Message',1) 
              with ( MessageID INT) ox  
              WHERE MessageID = ox.MessageID  
于 2012-05-31T22:53:41.367 回答
0
  XML Format
  <?xml version="1.0" encoding="utf-8" ?>
  <Messages>
    <Message MessageID='33' />
    <Message MessageID='34' />
    <Message MessageID='20' />   
  </Messages>

 in Stored Procedure
  UPDATE TableName   SET Status='A'          
     WHERE MessageID IN
     (
           select *  from OPENXML  (@idoc, '/Messages/Message',1) with ( MessageID INT )        
              )
于 2012-05-31T22:57:06.187 回答
0

您正在检索Message需要节点列表的MessageID节点列表。

SELECT MessageID  
FROM OPENXML (@idoc, '/Message/MessageID',2) 
WITH (MessageID INT '.') 
于 2012-05-31T06:42:28.120 回答