Click here to Skip to main content
16,021,181 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
hi all



XML
<AllowanceDeduction>
  <Deduction Name=" ROW 1" Amount="-99" />
  <allowance Name="ROW 2" Amount="88" />
</AllowanceDeduction>



I have a xml schema above like that



I want out put as follows

allowanceName allowanceamount  deductionName dectionAmount
ROW-2                 88                             ROW 1               -99


Please help me guys ..its very urgnet...
thanks
in advance


mail me [e-mail removed — SA]
[Re-posted Retrieve values from xml[^] — SA]
Posted
Updated 6-Mar-15 9:35am
v3
Comments
Sergey Alexandrovich Kryukov 6-Mar-15 15:29pm    
Please don't re-post, this is considered as abuse, by apparent reasons. Help with what? Output where? This is not a question, and it is not urgent.
What have you tried so far?
There is a number of ways to parse XML, read about it, choose what's convenient for you; all documentation is very clear.
—SA

1 solution

Like this:
SQL
DECLARE @myDoc xml
SET @myDoc = '<AllowanceDeduction>
  <Deduction Name=" ROW 1" Amount="-99" />
  <allowance Name="ROW 2" Amount="88" />
</AllowanceDeduction>'

select 
	@myDoc.value('(/AllowanceDeduction/allowance/@Name)[1]', 'varchar(10)' ) as allowanceName,
	@myDoc.value('(/AllowanceDeduction/allowance/@Amount)[1]', 'int' ) as allowanceAmount,
	@myDoc.value('(/AllowanceDeduction/Deduction/@Name)[1]', 'varchar(10)' ) as deductionName,
	@myDoc.value('(/AllowanceDeduction/Deduction/@Amount)[1]', 'int' ) as deductionAmount


Still, please remember:
1) I tmight be urgent for you, but we all are here to help, and we do this in out free time
2) Never ever publish yout email address like this, if you don't like spams...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900