我有一点问题,我从互联网上获取此代码,并将其更改为我自己使用。我运行样本,它工作正常,没问题。在我为我的程序更改它之后,它不显示任何错误,仅 0行受影响。事实证明,xml列没有返回任何内容。我希望有一些暗示。
declare @input XML
set @input = '<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<CurrencyTransact>
<BCurrencyCode>USD</BCurrencyCode>
<StockBalance>18000.00</StockBalance>
</CurrencyTransact>
<CurrencyTransact>
<BCurrencyCode>MYR</BCurrencyCode>
<StockBalance>30000.00</StockBalance>
</CurrencyTransact>
;with GrabXML AS
(
select
CurrencyBal.value('@BCurrencyCode', 'varchar(10)') as 'BCurrencyCode',
CurrencyBal.value('@StockBalance', 'decimal(18,2)') as 'StockBalance'
from
@input.nodes('/NewDataSet/CurrencyTransact') as n(CurrencyBal)
)
update dbo.Currency
set StockBalance = g.StockBalance
from GrabXML g
where dbo.Currency.CurrencyCode = g.BCurrencyCode
答案 0 :(得分:1)
我只是改变了这一行,使其有效。问题解决了!
CurrencyBal.value('(BCurrencyCode)[1]', 'varchar(10)') as 'BCurrencyCode',
CurrencyBal.value('(StockBalance)[1]', 'decimal(18,2)') as 'StockBalance'