Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 861547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:59:42+00:00 2026-05-15T08:59:42+00:00

I am accepting an input parameter of xml type so that i can accept

  • 0

I am accepting an input parameter of xml type so that i can accept a list of insurance plans on a transaction. I need to take the xml parameter and shred it into a tale variable so that i can process some logic. How can i shred the XML into my table variable.

Here’s a script to create a sample table with data in it;

/*
CREATE TABLE PlanData(PlanPos INT IDENTITY, PayerDX INT, PlanDX INT, PayPct DECIMAL(6,2))

INSERT PlanData(PayerDX, PlanDX, PayPct)
VALUES(10, 20, 80)
INSERT PlanData(PayerDX, PlanDX, PayPct)
VALUES(25, 50, 10)

drop table PlanData
*/

DECLARE @xmlPlans XML
SET @xmlPlans = (SELECT PlanPos, PayerDX, PlanDX, PayPct
                 FROM PlanData
                 ORDER BY PlanPos
                 FOR XML RAW('plan'), ROOT('plans')
                 )

print CAST(@xmlPlans AS NVARCHAR(max))

/* We must convert the XML passed in containing all of the insurance payer plan 
data into a usable format for the current scoping. */
DECLARE @tblPlans TABLE(PlanPos INT, IPDX INT, IPPDX INT, PayPct decimal(6, 2))   

--   /* Note that the table is built in order from Primary through the last plan */
--   INSERT @tblPlans (PlanPos, IPDX, IPPDX, PayPct)
--   SELECT x.item.value('@PlanPos[1]', 'INT') AS PlanPos,
--      x.item.VALUE('@IPDX[1]', 'INT') AS IPDX,
--      x.item.VALUE('@IPPDX[1]', 'INT') AS IPPDX,
--      x.item.VALUE('@PayPct[1]', 'decimal(6, 2)') AS PayPct
--   FROM @xmlPlans.nodes('//items/item') AS x(item)


   INSERT @tblPlans (PlanPos, IPDX, IPPDX, PayPct)
   SELECT T.plann.value('@PlanPos', 'int') AS PlanPos
      ,T.plann.VALUE('@PayerDX', 'INT') AS IPDX
      ,T.plann.VALUE('@PlanDX', 'INT') AS IPPDX
      ,T.plann.VALUE('@PayPct', 'decimal(6, 2)') AS PayPct
   FROM @xmlPlans.nodes('plans/plan') as T(plann)


---- Attribute-centered XML
--DECLARE @data XML
--SET @data = '<data><customer id="1" name="Allied Industries"/><customer id="2" name="Trades International"/></data>';
--
--DECLARE @tblCust TABLE(id INT, [name] VARCHAR(20))
--
--
---- Using the value() method
--INSERT @tblCust (id, [name])
--SELECT T.customer.value('@id', 'INT') AS customer_id,
--       T.customer.value('@name', 'VARCHAR(20)') AS customer_name
--FROM @data.nodes('data/customer') AS T(customer);   
--
--SELECT id AS dx, name AS CustName FROM @tblCust



--   SELECT x.item.value('@PlanPos[1]', 'INT') AS PlanPos,
--      x.item.VALUE('@IPDX[1]', 'INT') AS IPDX,
--      x.item.VALUE('@IPPDX[1]', 'INT') AS IPPDX,
--      x.item.VALUE('@PayPct[1]', 'decimal(6, 2)') AS PayPct
--   FROM @xmlPlans.nodes('//items/item') AS x

   SELECT
      p.PlanPos AS PlanPos,
      p.IPDX AS IPDX,
      p.IPPDX AS IPPDX,
      p.PayPct AS PayPct
   FROM @tblPlans p

You will also see me attempts at it that are failing.

Thank you,

Brian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:59:43+00:00Added an answer on May 15, 2026 at 8:59 am

    OK, I tried your tables and I get the following output from your FOR XML RAW..... statement:

    <plans>
      <plan PlanPos="1" PayerDX="10" PlanDX="20" PayPct="80.00" />
      <plan PlanPos="2" PayerDX="25" PlanDX="50" PayPct="10.00" />
    </plans>
    

    Now which of these attributes do you want to put into which of the columns of the table variable?? Your attribute names used in the x.item.value(...) statements just didn’t match what is really available in the XML result from your FOR XML statement.

    Try this:

    DECLARE @tblPlans TABLE(PlanPos INT, IPDX INT, IPPDX INT, PayPct decimal(6, 2))   
    
    INSERT @tblPlans (PlanPos, IPDX, IPPDX, PayPct)
      SELECT x.item.value('@PlanPos[1]', 'INT') AS PlanPos,
          x.item.value('@PayerDX[1]', 'INT') AS IPDX,
          x.item.value('@PlanDX[1]', 'INT') AS IPPDX,
          x.item.value('@PayPct[1]', 'decimal(6, 2)') AS PayPct
       FROM @xmlPlans.nodes('//plans/plan') AS x(item)
    
    SELECT * FROM @tblPlans
    

    I get this output from that:

    PlanPos IPDX    IPPDX   PayPct
      1          10      20      80.00
      2          25      50      10.00
    

    Or what is it that you’re really looking for??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Accepting the possibility of extreme ridicule, I must admit that I really miss sun
I am passing the parameter to the function as a var type. It is
I am accepting the path through command line input. When I do dir=opendir(args[1]); it
What is the best way to create a webservice for accepting an image. The
Is it OK if the same OpenSSL context is used by several different accepting
I have a very painful library which, at the moment, is accepting a C#
My C++ framework has Buttons. A Button derives from Control. So a function accepting
Is accessing a bool field atomic in C#? In particular, do I need to
I need to make some reflective method calls in Java. Those calls will include
I'm relatively new to utilizing web services. I'm trying to create one that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.