Author |
Topic |
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-07-07 : 18:53:13
|
I have field called deposit in sql database for each client I have more than one deposit value, I need to add those values from database and display the result in the table. How can I add them up? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-07-07 : 19:19:00
|
Could you post the DDL for your table that you are referring to and show us a data example of what the output should look like?Tara |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-07-07 : 19:34:19
|
I am not sure what is DLL means but let me try to show more..sql table fields calledclientid deposits1 10002 2001 300I need to add up fields for deposits for cliendid field 1's 1000+300 and display this to table in the web form as total deposits = 1300 for clientid 1 Does it make sense? |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-07-07 : 19:37:10
|
SELECT SUM(deposits)FROM YourTableWHERE clientid = 1Tara |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-07-07 : 20:12:27
|
Thank you this works, but when I run this result comes under the No column name because I don't have column for totalshere my question now,Dim rs As OleDb.OleDbDataReader = cmd.ExecuteReaderwhile rs.readtablecell.text = rs.item("I don't have column name for it")to read from database and display to table. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-07-07 : 20:13:32
|
SELECT SUM(deposits) AS SumDeposits <--or whatever you want to name itFROM YourTableWHERE clientid = 1Tara |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-07-07 : 20:15:02
|
then this SUMdeposits name would appear in my table in the database, I don't want that to happen. |
 |
|
jhermiz
3564 Posts |
Posted - 2005-07-07 : 21:59:06
|
quote: Originally posted by notsosuper then this SUMdeposits name would appear in my table in the database, I don't want that to happen.
No, it wont, tara just gave the column an alias name.You don't want to store totals inside of a table otherwise maintaining it could get very difficult.When you perform an aggreate on a specific column then SQL Server does not automatically name that column, hence the "No column name" in Query Analyzer.To resolve this you simply give the column the name of your choice.SELECT SUM(deposits) As WhateverYouWantHere FROM YourTableWHERE ClientID = 1Then in your vb / asp code you simply reference it as:rs("WhateverYouWantHere")Jon Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-07-07 : 22:12:37
|
You should use ExecuteScalar() if you have a command that returns a single value; the name of the column isn't an issue in that case.Also, use SqlClient and not OleDB if you are connecting to a SQL database in .NET.- Jeff |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-07-07 : 22:35:13
|
If you do not know how to do this, you need to take a course in the basics of SQL.Here are a couple of free online courses that are a good introduction to the basics of SQL. They should be taken in sequence.http://www.sqlcourse.com/ http://sqlcourse2.com/ The following site has a number of free training classes available: HTML, XML, SQL, .NET, Scripting, Building web sites, etc. It also offers online quizzes.This SQL Course includes a page where you can run your own queries, and a quiz.: http://www.w3schools.com/sql/default.asp Home Page showing all courses: http://www.w3schools.com/default.asp This site has a online tutorial about SQL. http://www.1keydata.com/sql/sql.html These courses are not meant to cover advanced features and programming techniques. Some of these courses use versions of SQL with certain features not available in SQL Server. Please refer to SQL Server Books Online for the exact syntax for SQL Server Transact-SQL.quote: Originally posted by notsosuper I have field called deposit in sql database for each client I have more than one deposit value, I need to add those values from database and display the result in the table. How can I add them up?
CODO ERGO SUM |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-07-08 : 11:01:37
|
I have done it, thank you all! |
 |
|
|