Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2003, 10:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default sum'ing columns after a filter (in rs)

All,

I previously asked about getting the sum of a columnin a db. I figured out to add an item to SELECT statement to create a variable:

txtSQL.CommandText = "SELECT customer_number, past_due_30, SUM(total_due) AS 'intTotalDue'" & _
                     "FROM accounts_receivable" & _
                     "WHERE past_due_30 > '0'" & _
                     "ORDER BY past_due_30 DESC ;"

But this appears to create a variable named intTotalDue that is the total of the entire column (total_due) from the database, not just the total of the column (total_due) in the recordset.. How do I total just the filtered record's column? Do I have to create a nested SELECT statement or can I use the HAVING clause - if so how?

thanks a lot,
Nick
 
Old August 6th, 2003, 06:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A recordset is made up of columns. That means you can't get a single value for the whole recordset, it will return that value for each row of the recordset.

Use an output parameter to a stored procedure.
http://www.aspalliance.com/stevesmit...les/sprocs.asp

regards
David Cameron
 
Old August 21st, 2003, 03:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Only those records that match your criteria (WHERE past_due_30 > '0') should be summed. SUM() should only sum those records matching the criteria, not all the records in the table.

Cheers
Ken

www.adOpenStatic.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide Columns, Filter & Copy Visable to new wrkbk dursta Excel VBA 1 June 4th, 2007 06:17 AM
rs.filter in asp.net - Please help ivanv ASP.NET 2.0 Basics 0 May 13th, 2007 05:14 AM
how to filter out unwanted selection in rs paging gilgalbiblewheel Classic ASP Databases 1 October 18th, 2004 07:21 AM
RS Manager and RS Server on 2 different computers Choose File BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 22nd, 2004 10:56 AM
NEW QUESTION - sum'ing filtered columns nlicata Classic ASP Databases 0 August 6th, 2003 10:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.