SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding a SUM column to SQL query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

johnmitch38
Starting Member

United Kingdom
9 Posts

Posted - 10/29/2013 :  13:14:42  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
5907 Posts

Posted - 10/29/2013 :  13:44:31  Show Profile  Reply with Quote
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

United Kingdom
9 Posts

Posted - 10/30/2013 :  04:50:55  Show Profile  Reply with Quote
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

India
22713 Posts

Posted - 10/30/2013 :  05:23:52  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
52249 Posts

Posted - 10/30/2013 :  07:58:10  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000