Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED HELP WITH SQL STATEMENT

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
In one SQL statement I am trying to select all the individual amounts in the column of a table and the sum of those amounts.
I can do this with two separate statements but not all in one statement. Is Possible????

Thank You, anybody
TNN, Tom


TOM
 
Can you provide an example of the first few entries in the data table and indicate the expected (required) result set. It looks like this may be striaghtforward but need to see the context of the issue.
Steve
 

You can submit a SQL script like this.
[tt]
Declare @sum decimal(10,2)

Select @sum=sum(col1) From table

Select col1, @sum As SumCol1 From table
[/tt]
OR you could do the following though it is less efficient.
[tt]
Select col1, SumCol1=(Select sum(col1) From table)
From table[/tt] Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
StevenK,
I am using an access 2000 database. Using SQL via ADO in VB6.0.

My table is a multicolumn table. I want to select or show all the number amounts in a particular single column and get a total of these amounts.

TNN, Tom
TNPAYROLL@AOL.COM


TOM
 
Terry,
I am using an access 2000 database. I am using SQL via ADO in VB6.0.
I tried your second example in the SQL Server forum but can't make it work. Seems like it should.

The two separate statements that work as follows:

SELECT WAMT FROM EMPEARNPERWAGE
WHERE EMPNO=62

SELECT
SUM(WAMT)
AS TOTAL FROM EMPEARNPERWAGE
WHERE EMPNO=62
These two statements work fine but I need to put them together into one statement.

Posted this also in access forum in case you went there.

Thank You, TNN, Tom
TNPAYROLL@AOL.COM


TOM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top