私は以下を持っています
最初のテーブル
Declare @t1 Table(Id int , PaymentXML XML)
Insert Into @t1
Select 1, '<CreditCard>
<cc_display_name />
<cc_type>MasterCard</cc_type>
<cc_no>************5811</cc_no>
<cc_expire_month>4</cc_expire_month>
<cc_expire_year>2007</cc_expire_year>
</CreditCard>' Union All
Select 2 , '<CreditCard>
<cc_display_name />
<cc_type>MasterCard</cc_type>
<cc_no>****1234567890</cc_no>
<cc_expire_month>3</cc_expire_month>
<cc_expire_year>2010</cc_expire_year>
</CreditCard>' Union All
Select 3 , '<CreditCard>
<cc_display_name />
<cc_type>MasterCard</cc_type>
<cc_no>****45678</cc_no>
<cc_expire_month>10</cc_expire_month>
<cc_expire_year>2011</cc_expire_year>
</CreditCard>' Union All
Select 4 , '<CreditCard>
<cc_display_name />
<cc_type>MasterCard</cc_type>
<cc_no>****1234567890</cc_no>
<cc_expire_month>5</cc_expire_month>
<cc_expire_year>1997</cc_expire_year>
</CreditCard>'
Select * From @t1
セカンドテーブル
Declare @t2 Table(Id int)
Insert Into @t2 Select 1 Union All Select 2
Select * From @t2
@t1 および @t2 テーブルの一致する行ごとに、PaymentXML 列ノードが次のように更新されるように、更新ステートメントを記述する必要があります。
a) 空白になります (つまり )
b) 空白になります (つまり )
c) ゼロ (0) (つまり 0 ) になります。
d) ゼロ (0) (つまり 0 ) になります。
私は非常に基本的なショットを与えましたが、xquery は初めてなので助けが必要です
DECLARE @cc_type VARCHAR(10)
SELECT @cc_type = ''
Update @t1
SET PaymentXML.modify(
'
replace value of (/CreditCard/@cc_type)[1]
with sql:variable("@cc_type")
')
From @t1 a
Join @t2 b On a.Id = b.Id
前もって感謝します