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 8383087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:04:36+00:00 2026-06-09T17:04:36+00:00

I am trying to parse a simple XML file. As soon as I un

  • 0

I am trying to parse a simple XML file. As soon as I un comment the insert statement it gives me invalid column errors.

drop table #TEMP
drop table #TEMP_T

declare @XMl_DATA AS XML
set @XMl_DATA =
'<DocumentElement>
  <Att_Table>
    <L_ATTR_CD>GAS_FLOW_START_DATE</L_ATTR_CD>
    <L_ATTR_DESC>GAS FLOW START DATE</L_ATTR_DESC>
    <L_ATTR_VALUE>01/01/2012</L_ATTR_VALUE>
    <R_ATTR_CD>EX_CTRCT_CO_ID</R_ATTR_CD>
    <R_ATTR_DESC>EXCLUDE GID(S)</R_ATTR_DESC>
    <R_ATTR_VALUE />
  </Att_Table>
  <Att_Table>
    <L_ATTR_CD>GAS_FLOW_END_DATE</L_ATTR_CD>
    <L_ATTR_DESC>GAS FLOW END DATE</L_ATTR_DESC>
    <L_ATTR_VALUE>01/31/2012</L_ATTR_VALUE>
    <R_ATTR_CD>EX_CTRCT_NBR</R_ATTR_CD>
    <R_ATTR_DESC>EXCLUDE CONTRACT NUMBER(S)</R_ATTR_DESC>
    <R_ATTR_VALUE />
  </Att_Table>
  <Att_Table>
    <L_ATTR_CD>CTRCT_CO_ID</L_ATTR_CD>
    <L_ATTR_DESC>GID(S)</L_ATTR_DESC>
    <L_ATTR_VALUE />
    <R_ATTR_CD>EX_RATE_CMPNT_CD</R_ATTR_CD>
    <R_ATTR_DESC>EXCLUDE RATE COMPONENT CODE(S)</R_ATTR_DESC>
    <R_ATTR_VALUE />
  </Att_Table>
  <Att_Table>
    <L_ATTR_CD>CTRCT_NBR</L_ATTR_CD>
    <L_ATTR_DESC>DART STYLE CONTRACT NUMBER(S)</L_ATTR_DESC>
    <L_ATTR_VALUE />
    <R_ATTR_CD>EX_PT_ID_NBR</R_ATTR_CD>
    <R_ATTR_DESC>EXCLIDE POINT ID NUMBER(S)</R_ATTR_DESC>
    <R_ATTR_VALUE />
  </Att_Table>
  </DocumentElement>'

Temp table:

CREATE TABLE #TEMP_T 
    (
        ID INT IDENTITY(1,1), 
        ATT_CD VARCHAR(50), 
        ATT_CD_VALUE VARCHAR(1000)
    )

SELECT 
    cast(Colx.query('data(L_ATTR_CD)') as varchar(max))as L_ATTR_CD,
    cast(Colx.query('data(L_ATTR_VALUE)') as varchar(max))as L_ATTR_CD_VALUE,
    cast(Colx.query('data(R_ATTR_CD)') as varchar(max)) as R_ATTR_CD,
    cast(Colx.query('data(R_ATTR_VALUE)') as varchar(max))as R_ATTR_CD_VALUE
    INTO #TEMP 
    FROM @XMl_DATA.nodes('DocumentElement/Att_Table') AS T(Colx)

    --INSERT INTO #TEMP_T(ATT_CD,ATT_CD_VALUE)
    --SELECT LTRIM(RTRIM(L_ATT_CD)),LTRIM(RTRIM(L_ATT_CD_VALUE)) 
    --FROM #TEMP 
    --WHERE L_ATT_CD_VALUE <> 'NO_DATA'


    --INSERT INTO #TEMP_T(ATT_CD,ATT_CD_VALUE)
    --SELECT LTRIM(RTRIM(R_ATT_CD)),LTRIM(RTRIM(R_ATT_CD_VALUE)) 
    --FROM #TEMP 
    --WHERE R_ATT_CD_VALUE <>'NO_DATA'

Output:

     select * from #TEMP_T
        select * from #TEMP 
  • 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-06-09T17:04:38+00:00Added an answer on June 9, 2026 at 5:04 pm

    Why don’t you just do something like this?

    -- define your XML structure and create the #TEMP_T table
    
    ;WITH ParsedData AS 
    (
        SELECT
            Colx.value('(L_ATTR_CD)[1]', 'varchar(50)') as L_ATTR_CD,
            Colx.value('(L_ATTR_VALUE)[1]', 'varchar(50)') as L_ATTR_CD_VALUE,
            Colx.value('(R_ATTR_CD)[1]', 'varchar(50)') as R_ATTR_CD,
            Colx.value('(R_ATTR_VALUE)[1]', 'varchar(50)') as R_ATTR_CD_VALUE
        FROM 
            @XMl_DATA.nodes('DocumentElement/Att_Table') AS T(Colx)
    )
    INSERT INTO #temp_T(ATT_CD, ATT_CD_VALUE)
        SELECT L_ATTR_CD, L_ATTR_CD_VALUE
        FROM parseddata
        UNION
        SELECT R_ATTR_CD, R_ATTR_CD_VALUE
        FROM parseddata
    

    This just parses the XML (much simpler than your approach, too!) and then inserts both the (L_ATTR_CD, L_ATTR_CD_VALUE) as well as the (R_ATTR_CD, R_ATTR_CD_VALUE) pairs into the temp table in a single go.

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

Sidebar

Related Questions

I'm trying to parse a simple XML file but I'm having trouble trying to
While trying to parse an xml file into table format, jQuery keeps closing my
I'm trying to parse an xml file that has the contents of a simple
I'm trying to parse a simple XML file in my j2me application. But the
I'm trying to parse an xml file using XML::Simple library. In a designed way
Trying to do a simple parse of an XML document. What's the easiest way
I am trying to create a very simple antlr grammar file which should parse
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>
I'm trying to parse an xml file to return a item with a specific
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply

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.