0

我正在使用 SQL Server 2005/2008 xml/xquery。我有以下 xml,我想返回<all><except>.

declare @x xml = '
<except>
  <x>1</x>
  <x>4</x>
</except>
<all>
  <x>1</x>
  <x>2</x>
  <x>3</x>
  <x>4</x>
</all>'
select @x.query('for $x in /all return $x') 
-- How to except the elements in <except>?

预期结果:<x>2</x><x>3</x>

4

1 回答 1

1

我一直在尝试并找到了一种解决方案。可以吗?

select @x.query('let $e := /all/x[not(. = /except/x)]
return $e')
于 2013-07-11T21:11:38.967 回答