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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:03:04+00:00 2026-05-27T02:03:04+00:00

Under a tight deadline and I know I can figure this out eventually but

  • 0

Under a tight deadline and I know I can figure this out eventually but I don’t have much time to do it on my own.

I have a table that has columns for customer id and account number among many other additional columns. There could be many accounts for a single customer (Many rows with the same customer id but different account number).

For each customer in the table I need to call a stored procedure and pass data from my table as xml in the following format. Notice that the xml is for all of the customers accounts.

<Accounts>
 <Account>
  <AccountNumber>12345</AccountNumber>
  <AccountStatus>Open</AccountStatus>
 </Account>
 <Account>
  <AccountNumber>54321</AccountNumber>
  <AccountStatus>Closed</AccountStatus>
 </Account>
</Accounts>  

So I guess I need help with 2 things. First, how to get the data in this xml format. I assuming I’ll use some variation of FOR XML. The other thing is how do I group by customer id and then call a sproc for each customer id?

  • 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-27T02:03:05+00:00Added an answer on May 27, 2026 at 2:03 am

    Something like this will work. This is one of the few cases for cursors.

    create table #a (CustomerID int, AccountNumber int, AccountStatus varchar(max))
    
    insert into #a values (1,12345,'Open')
    insert into #a values (1,54321,'Closed')
    insert into #a values (2,77777,'Open')
    insert into #a values (2,88888,'Closed')
    
    DECLARE @CustomerID int
    DECLARE @accounts xml
    
    DECLARE CurInvoice CURSOR READ_ONLY FAST_FORWARD FOR
        SELECT DISTINCT CustomerID 
        FROM #a  
    
    OPEN CurInvoice
    
    FETCH NEXT FROM CurInvoice INTO @CustomerID
    WHILE @@FETCH_STATUS = 0
        BEGIN
    
        set @accounts = (
        select AccountNumber,AccountStatus
        from #a
        where CustomerID = @CustomerID
        for xml path('Account'), root('Accounts'))
    
        exec MyProc @XmlInput = @accounts
    
    
    FETCH NEXT FROM CurInvoice INTO @CustomerID
    END
    CLOSE CurInvoice
    DEALLOCATE CurInvoice
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Under what circumstances would this or would this not be safe? I have a
Under Solution->Properties, I can set multiple start-up projects: I know that I can get
I am developing under Linux with pretty tight constraints on disk usage. I'd like
under Netbeans ,I created a project containing an interface i_object This interface represents the
Under WEB-INF/classes folder i have java class files structured in package hierarchy(e.g: com.company.app )
Under Windows 7 I created a custom autostart entry for an usb device. This
Under my VS2010 solution I've this situation: WEBSITE Library1 Library2 On global.asax.cs I initialize
Under normal circumstances, a VB.NET application of mine can check the ClientName environmental variable
I have a general gut feeling about the difference but I'm unable to pinpoint
Under vs10 msbuild.exe how can a specific project within a solution.sln be Ignored? I

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.