0

From my ASP.Net application I am generating XML and pass it as input data to stored procedure as below,

<Aprroval>
  <Approve>
    <is_nb_approved>false</is_nb_approved>
    <is_approved>true</is_approved>
    <is_submitted>true</is_submitted>
    <UserId>35</UserId>
    <ClientId>405</ClientId>
    <taskDate>2015-05-23T00:00:00</taskDate>
  </Approve>
  <Approve>
    <is_nb_approved>false</is_nb_approved>
    <is_approved>true</is_approved>
    <is_submitted>true</is_submitted>
    <UserId>35</UserId>
    <ClientId>405</ClientId>
    <taskDate>2015-05-24T00:00:00</taskDate>
  </Approve>
</Approval>

And below is my stored procedure,

create procedure UpdateTaskStatus(@XMLdata XML)
  AS

UPDATE [TT_TaskDetail] 
SET 
    is_approved=Row.t.value('(is_approved/text())[1]','bit'),
    is_nb_approved=Row.t.value('(is_nb_approved/text())[1]','bit'),
    is_submitted=Row.t.value('(is_submitted/text())[1]','bit')
FROM @XMLdata.nodes('/Aprroval/Aprrove') as Row(t)
WHERE user_id = Row.t.value('(UserId/text())[1]','int') 
  AND client_id = Row.t.value('(ClientId/text())[1]','int') 
  AND taskdate = Row.t.value('(taskDate/text())[1]','date')

But when I execute this stored procedure, I am getting return value as 0 and no record is getting updated. Any suggestions welcome.

2
  • Did you try just selecting from that xml? Commented Jun 15, 2015 at 19:18
  • Yes, not returning anything Commented Jun 15, 2015 at 19:24

2 Answers 2

1

You have 2 errors in your xml:

First is nonmatching root tags.

Second, more important, you are quering nodes('/Aprroval/Aprrove'), but inner tag is Approve not Aprrove.

Fiddle http://sqlfiddle.com/#!3/66b08/3

Sign up to request clarification or add additional context in comments.

Comments

1

Your outer tags do not match. Your opening tag says, "Aprroval" instead of "Approval". Once I corrected that, I was able to select from the XML without issue.

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.