0

I have a bit of problem, I get this code from the internet and i alter it for my own use. i run the sample and it works fine, no problem. after i change it for my program, it doesnt show any error, just 0 rows affected. turned out, the xml column return nothing.I'm hoping for some hint.

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 Answer 1

1

i just altered this line to make it works.Problem solve!

   CurrencyBal.value('(BCurrencyCode)[1]', 'varchar(10)') as 'BCurrencyCode',
   CurrencyBal.value('(StockBalance)[1]', 'decimal(18,2)') as 'StockBalance'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.