2015-10-05 55 views
0

我有一些問題,我從互聯網上獲取此代碼,並將其改爲供我自己使用。我運行示例,它工作正常,沒有問題。在我改變它爲我的程序後,它不顯示任何錯誤,只是0行受影響。結果,xml列沒有任何返回。我希望得到一些提示。來自XML的SQL更新始終返回空值

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 

回答

1

我只是改變了這一行,使其works.Problem解決!

CurrencyBal.value('(BCurrencyCode)[1]', 'varchar(10)') as 'BCurrencyCode', 
    CurrencyBal.value('(StockBalance)[1]', 'decimal(18,2)') as 'StockBalance'