How to parse the xml using t- sql

  • declare @appro_xml xml ;

    set @appro_xml='

    1020210

    11

    12

    14

    15

    '

    select

    x.col.value('SolicitationID[1]','INT')AS request_id ,

    x.col.value('DeclineReasonCode[1]','varchar(500)')AS DeclineReasonCode

    FROM @appro_xml.nodes('//ScoreAndDataRetrievalRequest') x(col)

    --CROSS APPLY col.nodes('DeclineReasonCode') d(dec)

  • xml file

    declare @appro_xml xml

    set @appro_xml='

    1020

    210

    11

    12

    14

    15

    '

  • Use the tags [ code="xml" ] and [ /code ] without the spaces 😉

    declare @appro_xml xml ;

    set @appro_xml='

    1020

    210

    11

    12

    14

    15

    '

    select

    x.col.value('SolicitationID[1]','INT')AS request_id ,

    x.col.value('DeclineReasonCode[1]','varchar(500)')AS DeclineReasonCode

    FROM @appro_xml.nodes('//ScoreAndDataRetrievalRequest') x(col)

    --CROSS APPLY col.nodes('DeclineReasonCode') d(dec)

    Greets

    Flo

  • 1020

    210

    11

    12

    14

    15

  • By the way: What's the question?

  • I asked both the same things on his other post, which appears to be pretty much the same junk.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • t-sql

    DeclineReasonCode node

    not returning all node value

    11,12,13 etc

  • declare @appro_xml xml ;

    set @appro_xml='

    1020

    210

    11

    12

    14

    15

    '

    select

    x.col.value('../../SolicitationID[1]','INT')AS request_id ,

    x.col.value('../../DeclineReasonCode[1]','varchar(500)')AS DeclineReasonCode,

    x.col.value('(./text())[1]', 'varchar(100)') AS DeclineReasonCode

    FROM @appro_xml.nodes('//ScoreAndDataRetrievalRequest/DeclineReasonCode/DeclineReasonCode') x(col)

    --CROSS APPLY col.nodes('DeclineReasonCode') d(dec)

  • My hole xml look like

    declare @appro_xml xml

    set @appro_xml='

    1020

    210

    1001

    24

    19

    11

    12

    14

    15

    1

    0

    1

    1

    1

    0

    0

    0

    Company

    168

    ghfh

    Steve

    Martin

    7

    89082

    28.50

    10835

    1020

    623-17-8923

    John

    Hill

    7

    205008

    71.50

    10835

    1020

    623-22-5433

    Company

    201

    sjkfhjklfhasdkfhsd

    Joseph

    Brenann

    7

    102001

    50.00

    91876

    1020

    233-21-7654

    Curt

    Provenzo

    7

    102344

    50.00

    91876

    1020

    623-14-2314

    Indvidual

    177

    afsjkhf

    Tim Denniston

    544-12-2354

    1

    200345

    Limited

    1611 45 St.

    10 Downing St.

    Brooklyn

    NY

    USA

    11204

    Jason Houseman

    761-33-3354

    1

    150000

    UnLimited

    c/o National Realty and Development Corp.

    3 Manhattanville Road

    Purchase

    PA

    USA

    10577

    Michael J. Prendergast

    623-14-2987

    1

    90000

    Limited

    301 Exchange Boulevard

    Rochester

    NY

    USA

    11204

    '

    select

    --x.col.value('../../SolicitationID[1]','INT')AS request_id ,

    x.col.value('SolicitationID[1]','INT')AS request_id ,

    x.col.value('DeclineReasonCode[1]', 'varchar(100)') AS DeclineReasonCode

    FROM @appro_xml.nodes('//ScoreAndDataRetrievalRequest') x(col)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply