Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15713

Sum data from two tables

$
0
0
Hello Vbforums

I need to sum data from two tables.

This is the illustration

Table MTbl

ID...............Tarif
1 ................200

Table Act_tbl

ID....................Recette
1.......................300

I'm using sqlite3 and RC5

This is my attempt:
Code:

StrSql = "select  tarif, recette  from MTbl " & _
  " inner join Act_tbl on MTbl.Id = Act_tbl.ID"
    Set Rs = Cnn.OpenRecordset(StrSql)
    Do While Not Rs.EOF
    Debug.Print val(Rs!Recette) + val(Rs!tarif)
      Rs.MoveNext
      Loop

The output
200
200
500

Another attempt:
Code:

StrSql = "select  tarif, recette  from MTbl " & _
  " inner join Act_tbl on MTbl.Id = Act_tbl.ID group by Act_tbl.ID"
    Set Rs = Cnn.OpenRecordset(StrSql)
    Do While Not Rs.EOF
    Debug.Print val(Rs!Recette) + val(Rs!tarif)
      Rs.MoveNext
      Loop

The output
200
I want the output to be 500
Any help is much appreciated

Viewing all articles
Browse latest Browse all 15713

Trending Articles



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