• Christopher Ford (3/26/2008)


    The light finally went off...

    for each "section" I need to cross apply it to do what I want.

    Example below:

    SELECT

    x.value('UnparsedName[1]', 'VARCHAR(20)') as Name

    ,l.value('@BusinessType', 'varchar(20)') as BusinessType

    ,CAST(CONVERT(varchar(20),l.query('HighBalanceAmount/text()')) as money) as HighBalanceAmount

    FROM ScreeningXML myXML

    CROSS APPLY xmlNode.nodes('/MORTGAGEDATA/BORROWER') E(x)

    CROSS APPLY xmlNode.nodes('/MORTGAGEDATA/CREDITREPORT/MERGEDLIABILITY') M(l)

    Sorry I just saw your previous question. I think I misunderstood your question though. Is borrower related to CREDITREPORT in any way? If so, it's not readily apparent (to me anyway) from your XQuery. I thought you were asking how to query multiple MERGEDLIABILITY nodes under a single CREDITRPORT node, like this:

    DECLARE @x xml;

    SET @x= '

    <CREDITREPORT CREDITREPORTID="CRRept0001" CreditReportType="Merge" MergeType="ListAndStack" EquifaxIncludedIndicator="N"

    ExperianIncludedIndicator="Y" TransUnionIncludedIndicator="N">

    <CreditReportIdentifier>xxxxx_xxx938</CreditReportIdentifier>

    <LastUpdatedDate>2006-04-10</LastUpdatedDate>

    <MERGEDLIABILITY ScoreTypeCode="Non" IndustryCode="FB" ICText="Mortgage Brokers" CollectionCode="" CollectionText=""

    MERGEDLIABILITYID="xxxxx_1_12" AccountOwnershipType="Individual" AccountStatusType="Transferred" AccountType="Mortgage"

    BusinessType="Finance" CreditLoanType="ConventionalRealEstateMortgage" CurrentDelinquencyRatingType="AsAgreed"

    ConsumerDisputeIndicator="N" DerogatoryDataIndicator="Y" BORROWERIDREFS="">

    <AccountIdentifier>******5563</AccountIdentifier>

    <AccountOpenedDate>2002-01</AccountOpenedDate>

    <AccountStatusDate>2002-12</AccountStatusDate>

    <CreditorName>OLYMPUS</CreditorName>

    <HighBalanceAmount>107200</HighBalanceAmount>

    <HighCreditAmount>107200</HighCreditAmount>

    <Late30DaysCount>0</Late30DaysCount>

    <Late60DaysCount>0</Late60DaysCount>

    <Late90DaysCount>0</Late90DaysCount>

    <MonthsReviewedCount>13</MonthsReviewedCount>

    <PaymentPatternData>NCCCCCCCCCCCC</PaymentPatternData>

    <PaymentPatternStartDate>2002-12</PaymentPatternStartDate>

    <ReportedDate>2002-12</ReportedDate>

    <TermMonths>360</TermMonths>

    <CREDITCOMMENT CommentSource="RepositoryBureau">

    <Comment>Account transferred to another lender</Comment>

    </CREDITCOMMENT>

    <CREDITCOMMENT CommentSource="RepositoryBureau">

    <Comment>BaseStatus code `05` - TRANSFER</Comment>

    </CREDITCOMMENT>

    </MERGEDLIABILITY>

    <MERGEDLIABILITY ScoreTypeCode="Non" IndustryCode="FB" ICText="Mortgage Brokers" CollectionCode="" CollectionText=""

    MERGEDLIABILITYID="yyyyy_1_13" AccountOwnershipType="Individual" AccountStatusType="Transferred" AccountType="Mortgage"

    BusinessType="Finance" CreditLoanType="ConventionalRealEstateMortgage" CurrentDelinquencyRatingType="AsAgreed"

    ConsumerDisputeIndicator="N" DerogatoryDataIndicator="Y" BORROWERIDREFS="">

    <AccountIdentifier>******5563</AccountIdentifier>

    <AccountOpenedDate>2003-01</AccountOpenedDate>

    <AccountStatusDate>2004-09</AccountStatusDate>

    <CreditorName>OLYMPUS</CreditorName>

    <HighBalanceAmount>999999</HighBalanceAmount>

    <HighCreditAmount>999999</HighCreditAmount>

    <Late30DaysCount>0</Late30DaysCount>

    <Late60DaysCount>0</Late60DaysCount>

    <Late90DaysCount>0</Late90DaysCount>

    <MonthsReviewedCount>13</MonthsReviewedCount>

    <PaymentPatternData>NCCCCCCCCCCCC</PaymentPatternData>

    <PaymentPatternStartDate>2002-12</PaymentPatternStartDate>

    <ReportedDate>2002-12</ReportedDate>

    <TermMonths>360</TermMonths>

    <CREDITCOMMENT CommentSource="RepositoryBureau">

    <Comment>Account transferred to another lender</Comment>

    </CREDITCOMMENT>

    <CREDITCOMMENT CommentSource="RepositoryBureau">

    <Comment>BaseStatus code `05` - TRANSFER</Comment>

    </CREDITCOMMENT>

    </MERGEDLIABILITY>

    </CREDITREPORT> ';

    SELECT creditreport.value('@CREDITREPORTID[1]', 'varchar(100)') AS creditreportid,

    creditreport.value('LastUpdatedDate[1]', 'datetime') AS lastupdated,

    mergedliability.value('AccountOpenedDate[1]', 'varchar(100)') AS opendate,

    mergedliability.value('AccountStatusDate[1]', 'varchar(100)') AS statusdate,

    mergedliability.value('HighBalanceAmount[1]', 'varchar(100)') AS highbalance

    FROM @x.nodes('/CREDITREPORT') AS cr(creditreport)

    CROSS APPLY creditreport.nodes('MERGEDLIABILITY') AS ml(mergedliability);

    Note that you can cross apply the results of the .nodes() method and apply another .nodes() method to them like in this example. Also on this one I spelled out the column aliases to make them a little more readable.