Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.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 下次再见help@Mitch我在xml中多次在不同的decedent下使用文件路径节点。我无法找到一个查询来更新所有them@Mitch麦特我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。@米奇·麦特我在x_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

Sql 下次再见help@Mitch我在xml中多次在不同的decedent下使用文件路径节点。我无法找到一个查询来更新所有them@Mitch麦特我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。@米奇·麦特我在x

Sql 下次再见help@Mitch我在xml中多次在不同的decedent下使用文件路径节点。我无法找到一个查询来更新所有them@Mitch麦特我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。@米奇·麦特我在x,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,下次再见help@Mitch我在xml中多次在不同的decedent下使用文件路径节点。我无法找到一个查询来更新所有them@Mitch麦特我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。@米奇·麦特我在xml中的不同decedent下多次使用文件路径节点。我无法找到一个查询来更新所有them@Mitch我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。 <mediadata> &


下次再见help@Mitch我在xml中多次在不同的decedent下使用文件路径节点。我无法找到一个查询来更新所有them@Mitch麦特我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。@米奇·麦特我在xml中的不同decedent下多次使用文件路径节点。我无法找到一个查询来更新所有them@Mitch我已经准备好了,已经在脚本中复制粘贴了3次相同的update语句,以支持xml中的不同XPath。
 <mediadata>
  <image>
    <FileName>BUF2011-450</FileName>
    <FilePath>/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/BUF2011-450.jpg</FilePath>
    <Thumbnails>
      <Thumbnail>
        <FileName>BUF2011-450</FileName>
        <FilePath>/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/thumb_BUF2011-450_Large.jpg</FilePath>
      </Thumbnail>
      <Thumbnail>
        <FileName>BUF2011-450</FileName>
        <FilePath>/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/thumb_BUF2011-450_Small.jpg</FilePath>
      </Thumbnail>
    </Thumbnails>
  </image>
</mediadata>
declare @T table(XMLCol xml)

insert into @T values
('<image>
    <FileName>Tim+bottom</FileName>
    <FilePath>/Top+Bottom/AFX8995+450.jpg</FilePath>
  </image>')

update T set
  XMLCol.modify('replace value of (/image/FilePath[1]/text())[1] 
                 with sql:column("T2.FilePath")')
from @T as T
  cross apply (select replace(XMLCol.value('(/image/FilePath)[1]', 
                                           'varchar(100)'), 
                              '+', 
                              '_')
              ) as T2(FilePath)      
update T set
  XMLCol.modify('replace value of (/image/FilePath[1]/text())[1] 
                 with sql:column("T2.FilePath")')
from YourTable as T
  cross apply (select replace(XMLCol.value('(/image/FilePath)[1]', 
                                           'varchar(100)'), 
                              '+', 
                              '_')
              ) as T2(FilePath)      
where T.ID = 1
-- Test table
declare @T table(ID int, XMLCol xml)

-- Sample data
insert into @T values
(1,
 '<mediadata>
    <image>
      <FileName>BUF2011-450</FileName>
      <FilePath>1/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/BUF2011-450.jpg</FilePath>
      <Thumbnails>
        <Thumbnail>
          <FileName>BUF2011-450</FileName>
          <FilePath>2/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/thumb_BUF2011-450_Large.jpg</FilePath>
        </Thumbnail>
        <Thumbnail>
          <FileName>BUF2011-450</FileName>
          <FilePath>3/uploadedImages/Products/Indoor_Fun/Puzzles___Brain_Teasers/Puzzles/2000+_Pieces/thumb_BUF2011-450_Small.jpg</FilePath>
        </Thumbnail>
      </Thumbnails>
    </image>
  </mediadata>
')

-- ID for the row you need to update
declare @ID int
set @ID = 1

-- Loop variable, node to update
declare @Pos int
set @Pos = 1

-- The number of nodes to update
declare @Count int

-- Get the number of FilePath nodes
select @Count = XMLCol.query('count(//FilePath)').value('.', 'int')
from @T
where ID = @ID

while @Pos <= @Count
begin
  update T set
    XMLCol.modify('replace value of ((//FilePath)[sql:variable("@Pos")]/text())[1] 
                   with sql:column("T2.FilePath")')
  from @T as T
    cross apply (select replace(T.XMLCol.
                                  query('(//FilePath)[sql:variable("@Pos")]').
                                  value('.', 'varchar(100)'), 
                                '+', 
                                '_')
                ) as T2(FilePath)      
  where T.ID = @ID                 

  set @Pos += 1            
end