【发布时间】:2015-04-20 19:41:47
【问题描述】:
我必须根据该 XML 的某些条件更新表的 XML。示例 XML:
<CountryValues>
<CountryRow>
<CountryName>Brazil</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>1</Month>
<PlaceValue>0</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Brazil</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>2</Month>
<PlaceValue>0</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Brazil</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>3</Month>
<PlaceValue>0</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Brazil</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>4</Month>
<PlaceValue>10</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Australia</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>1</Month>
<PlaceValue>0</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Australia</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>1</Month>
<PlaceValue>0</PlaceValue>
</CountryRow>
<CountryRow>
<CountryName>Australia</CountryName>
<PlaceName>Place 1</PlaceName>
<Month>1</Month>
<PlaceValue>4</PlaceValue>
</CountryRow>
</CountryValues>
每个国家/地区可以有多个地点。我必须根据 Country 和 Places 进行分组,然后我必须将 PlaceValues 更新为 null for PlaceValue = 0 除了 0 紧接在 PlaceValue > 1 之前。此示例中的示例,对于 Country = Brazil 和 PlaceName = 1,PlaceValue 为Month1 到 Month2 将为 Null,但 Month3 将保持 0 与其前一个 Month4 相同,大于 0。
【问题讨论】:
-
“表的XML”是什么意思?出于某种原因,您有一个想要使用 T-SQL 更新的 XML 文件?您的表中有一个 XML 列?您要更新此列的
placeValue元素值吗? -
表中有 XML 列。我必须根据问题中提到的条件更新此列。我不能在 C# 中做到这一点,我只需要创建 Sql 脚本。
标签: sql sql-server xml tsql sqlxml