Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

Need a query to show data of a customer account in a report form...

$
0
0
Hi,

I have two tables:
1. SALESTABLE
2. RECEIPTSTABLE

I am now retrieving data of the above tables in separate datagridviews using the below code which is working fine.

Code:

    Private Sub LoadSales()
        Dim StrSql As String = "Select CUSTNO, CUSTNAME, INVNO, INVDATE, Sum(INVAMT) As INVAMT from SALESTABLE Where [CUSTNO] LIKE '" & txtSearchCustNo.Text & "' Group By CUSTNO, CUSTNAME, INVNO, INVDATE Order By CUSTNO ASC"
        Dim dt As New DataTable
        If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Exit Sub
        Me.dgvSales.DataSource = dt
        If dt Is Nothing Or dt.Rows.Count <= 0 Then
            Exit Sub
        End If
    End Sub

Code:

Private Sub LoadReceipts()
        Dim StrSql As String = "Select CUSTNO, CUSTNAME, RECEIPTNO, RECEIPTDATE, RECEIVEDAMT from RECEIPTSTABLE Where [CUSTNO] LIKE '" & txtSearchCustNo.Text & "' Order By RECEIPTNO ASC"
        Dim dt As New DataTable
        If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Exit Sub
        Me.dgvReceipts.DataSource = dt
        If dt Is Nothing Or dt.Rows.Count <= 0 Then
            Exit Sub
        End If
    End Sub

But I need a query that fetches both tables' data in one datagridview with one extra virtual column "BALANCE" as shown in the screenshots (attached).

Looking forward to your kind support.
Attached Images
  

Viewing all articles
Browse latest Browse all 2918

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>