Results 1 to 3 of 3

Thread: SQL sum & avg

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Dear VB users,

    In the next rows you can calculate via SQL the average & the sum.
    But where can I find the result?

    'Calculate the average
    Set RS = DB.OpenRecordset("select avg(MyField) from MyTabel") '
    RS.MoveLast
    'RESULT ? ? ? ? ? ? ? ? ?

    'Calculate the sum
    Set RS = DB.OpenRecordset("select sum(MyField) from MyTabel ") '
    RS.MoveLast
    'RESULT ? ? ? ? ? ? ? ? ?

    Thanks for your information.

    Nice regards,

    Michelle.

  2. #2
    Guest
    You can use

    Set RS = DB.OpenRecordset("select avg(MyField) as Avgval from MyTabel") '
    RS.MoveLast
    msgbox rs!avgval
    'or msgbox rs.fields(0).value

    Set RS = DB.OpenRecordset("select sum(MyField) as Sumval from MyTabel ") '
    RS.MoveLast
    msgbox rs!Sumval

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello sarun,

    Thanks for your information.

    Michelle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width