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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:21:35+00:00 2026-05-23T06:21:35+00:00

I am retrieving two or more tables data based on conditions, so I am

  • 0

I am retrieving two or more tables data based on conditions, so I am writing cursors in SQL server2005 like this:

create PROC [dbo].[uspCustomerInvoiceGetlist]
    @CustomerID varchar(20)
AS
BEGIN

    SELECT DeleteStatus,InvoiceID,CONVERT(varchar(16),CreationDate,101) + ' ' +
       CONVERT(varchar(16),CreationDate,8) as CreationDate,AccountNumber,Sum(Amount) as Amount from tblInvoiceDetails where CustomerID=@CustomerID Group By InvoiceID,CreationDate,AccountNumber,DeleteStatus
END

alter procedure uspCustomerInvoiceGetlist1(@CustomerID varchar(50)) as 
    Begin
        Declare @InvoiceID int, @Balance float
        Declare MyCur Cursor for select InvoiceID from tblInvoiceHeader where CustomerID=@CustomerID
        Open MyCur
        Fetch next from mycur into @InvoiceID
        While @@Fetch_Status=0 
        Begin
        set @Balance=(select sum(Balance) from tblInvoicePaymentDetails where CustomerId=@CustomerID and InvoiceId=@InvoiceID)
print @Balance      
if @Balance!=0

        SELECT h.DeleteStatus,h.InvoiceID,CONVERT(varchar(16),h.CreationDate,101) + ' ' +
       CONVERT(varchar(16),h.CreationDate,8) as CreationDate,h.AccountNumber,Sum(h.Amount) as Amount, @Balance as Balance from tblInvoiceDetails h inner join tblInvoicePaymentDetails p on h.CustomerID=p.CustomerID and h.InvoiceID=@InvoiceID
  Group By h.InvoiceID,h.CreationDate,h.AccountNumber,h.DeleteStatus
else
SELECT DeleteStatus,InvoiceID,CONVERT(varchar(16),CreationDate,101) + ' ' +
       CONVERT(varchar(16),CreationDate,8) as CreationDate,AccountNumber,Sum(Amount) as Amount, 0 as Balance from tblInvoiceDetails where CustomerID=@CustomerID and InvoiceID=@InvoiceID Group By InvoiceID,CreationDate,AccountNumber,DeleteStatus 

            Fetch Next From MyCUr into @InvoiceID
        End
        Close Mycur
        Deallocate Mycur
    End

output is correct like that (two outputs based on condition two are more)

 Status  InvoiceID     Date                 account no  Amount      Balance
    1   1009      06/21/2011 10:22:15       10009    450        350

Status  InvoiceID     Date                 account no   Amount      Balance
1   1010       06/21/2011 10:22:33        100000     690          0

But I can bind the all values (both) in grid view in ASP.NET 2.0. How is it possible?

  • 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-23T06:21:36+00:00Added an answer on May 23, 2026 at 6:21 am

    In the Front End, You will get Two DataTable.
    You just Combine those two DataTable into a Single One.
    And Bind the DataTable with the GridView.
    Merge like this:

       dt1.Merge(dt2);        //dt1 is the DataTable 1 and dt2 is the DataTable 2
    

    Get the Set of Tables as DataSet and Merge using For Loop: I have given code below:

      DataTable dtmerge = new DataTable();
      for (int i = 0; i < ds.Tables.Count; i++)             // ds is the DataSet
      {
          dtmerge.Merge(ds.Tables[i]);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there performance issues when retrieving and filtering data from views than from tables
One thing I've started doing more often recently is retrieving some data at the
I have two or more tables which hold values under the same column name.
I am trying to write a SQL query where I am joining two tables
I am getting these two errors when retrieving meta data from a remote webpage.
When retrieving a lookup code value from a table, some folks do this... Dim
I am retrieving three different sets of data (or what should be unique rows).
I have two tables FilesystemEntries and CacheEntries where there is an association of 0..1
I'm using C# and ASP.NET 3.5. Basically I'm retrieving a column of data from
Im looking at the following two ways of retrieving a value and storing it

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.