Help please with Select statement for calculation

Results 1 to 2 of 2

Thread: Help please with Select statement for calculation

  1. #1
    phudgins Guest

    Default Help please with Select statement for calculation

    Hello... I&#039ve got an Web-enabled Access database (using ASP)... just trying to query the database so that it totals a column. For example, I&#039ve got a column with prices in it... four records at 2 bucks each... how can the query total the column and give me 8 bucks total as the output? How does the query statement read? And, most importantly, PLEASE recommend a good query statement book/resource...can&#039t find anything!!! THANKS much

  2. #2
    Join Date
    Dec 1969

    Default RE: Help please with Select statement for calculat

    Something like this?<BR><BR>SELECT Sum(Prices) AS TheSum FROM table WHERE buyerID=&#039JONES113NO&#039<BR><BR>???<BR><BR>Thi s is not necessarily a good thing to do. You can&#039t get *both* an aggregate result *and* a simple set of records via the same query, so you end up doing two queries. You have to be very careful that you are working with exactly the same set of records in each query, something that can be problemetic in multi-user heavily updated systems.<BR><BR>Since building a sum is so easy to do in VBScript, you might be better off doing so as you process all the records in the recordset.<BR><BR>Something like:<BR><BR>&#060;%<BR>Sum = 0<BR>Do Until RS.EOF<BR>&nbsp;&nbsp;&nbsp;&nbsp;Sum = Sum + RS("Prices")<BR>&nbsp;&nbsp;&nbsp;&nbsp;... other processing of RS ...<BR>&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveNext<BR>Loop <BR>%&#062;<BR><BR>My favorite "launching point" for SQL questions:<BR><BR><BR><BR>I&#039d keep a copy on my own machine, were I you.<BR><BR><BR><BR>

Posting Permissions

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