正在更新部分SQL字段
我在一个sql表中有4900行,需要更新其中的一部分 结束日期是我需要更改的,但创建日期是唯一的 范例正在更新部分SQL字段,sql,Sql,我在一个sql表中有4900行,需要更新其中的一部分 结束日期是我需要更改的,但创建日期是唯一的 范例 <ArrayOfPromotionRuleBase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <PromotionRuleBase xsi:type="StartDatePromotionRule">
<ArrayOfPromotionRuleBase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PromotionRuleBase xsi:type="StartDatePromotionRule">
<StartDate>
2010-11-19T13:44:15.253
</StartDate>
</PromotionRuleBase>
<PromotionRuleBase xsi:type="ExpirationDatePromotionRule">
<ExpirationDate>
2014-01-01T00:00:00
</ExpirationDate>
</PromotionRuleBase>
</ArrayOfPromotionRuleBase>
2010-11-19T13:44:15.253
2014-01-01T00:00:00
如何仅使用过期日期部分来更改所有内容?因此,您有一个包含XML的字段,您只想更改其中的一部分。我认为SQL没有任何工具来编辑XML。您必须在应用程序中编写执行XML解析的代码,并从中进行更改。然而,这可能是一个相当昂贵的操作。如果您可以保证ExpidationDate只包含时间,那么可以使用正则表达式替换它 此正则表达式捕获group1中的日期。然后,您可以执行一个简单的替换:
<ExpirationDate.*>\s*(.*)\s*</ExpirationDate>
\s*(.*)\s*
列数据类型是什么?是xml吗?看看SQLXPath。我不想回答这个问题,因为我已经很久没有使用它了,但我相信这是你最好的方法。希望这能帮助你最终使用类似的方法,看起来效果很好更新促销集PromotionRuleData.modify('declare namespace ns=“value of(/ArrayOfPromotionRuleBase//ExpirationDate/text())[1]和“2015-01-01T00:00:00”)其中ID=2