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
 Execute SQL to add two columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

diva
Starting Member

United Kingdom
9 Posts

Posted - 06/12/2007 :  09:34:20  Show Profile  Reply with Quote
Hi All

could someone please advise how i would write my SQL code
so that it woould add the contents of two colums together
IE column J = 111.50 & column K = 256.30 then column N = 367.80

thanks

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 06/12/2007 :  09:38:45  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Select (colA + ColB) as ColC
From SomeTable


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 06/12/2007 :  09:45:19  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
What do you want to return if one of them is NULL?

Madhivanan

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

diva
Starting Member

United Kingdom
9 Posts

Posted - 06/12/2007 :  10:05:14  Show Profile  Reply with Quote
thank you very much I will try this

Go to Top of Page

diva
Starting Member

United Kingdom
9 Posts

Posted - 06/13/2007 :  08:34:35  Show Profile  Reply with Quote
Hi All

I have tried the above by writing the following

update RN_20000718115255CounterParty1
select ("option_price" + "Commission") as RN_20000718115255CounterParty1.[25] from RN_20000718115255CounterParty1

however it does not work. could you please advise what i have done wrong

thanks
Diva
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 06/13/2007 :  08:40:46  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
You should have told earlier that you are using UPDATE statement:

UPDATE RN_20000718115255CounterParty1
SET SomeCol = Coalesce(option_price, 0.00) + Coalesce(Commission, 0.00)
Where <some-optional-condition>


Note: Replace SomeCol with actual column name


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 06/13/2007 :  08:53:42  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
<<
select ("option_price" + "Commission")
>>

Are you adding column values or column names?

Madhivanan

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

diva
Starting Member

United Kingdom
9 Posts

Posted - 06/14/2007 :  04:34:39  Show Profile  Reply with Quote
I want to add the values together in Column Option_Price & Commission
so if in Option_Price it is 10 & in commission it is 12 the value in column 20 will be 32

Diva
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 06/14/2007 :  08:47:01  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
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.11 seconds. Powered By: Snitz Forums 2000