Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding a SUM column to SQL query

Author  Topic 

johnmitch38
Starting Member

9 Posts

Posted - 2013-10-29 : 13:14:42
Hi all,

I'm new to SQL so please tolerate my ignorance.

I have a pretty simple SQL query that has two columns that contains only numbers.

Is there a way i can add an extra column that simply subtracts the number in one column from number in the other column.

I query the data tables rather than have a live link so the .csv file gets overwritten every time i run the query.

Thanks,

JM

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-10-29 : 13:44:31
Here's one way:

select col1, col2, col2-col1 as [difference] from yourTable

Be One with the Optimizer
TG
Go to Top of Page

johnmitch38
Starting Member

9 Posts

Posted - 2013-10-30 : 04:50:55
Fantastic thanks.

On a similar topic, can i add a command that will sum a whole column and place the total at the bottom of the column?

JM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-10-30 : 05:23:52
Look for WITH ROLLUP in SQL Server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-30 : 07:58:10
quote:
Originally posted by johnmitch38

Fantastic thanks.

On a similar topic, can i add a command that will sum a whole column and place the total at the bottom of the column?

JM


see

http://technet.microsoft.com/en-us/library/bb522495(v=sql.100).aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -