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
 Execute SQL to add two columns

Author  Topic 

diva
Starting Member

9 Posts

Posted - 2007-06-12 : 09:34:20
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
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-12 : 09:38:45
[code]Select (colA + ColB) as ColC
From SomeTable[/code]

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-12 : 09:45:19
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

9 Posts

Posted - 2007-06-12 : 10:05:14
thank you very much I will try this

Go to Top of Page

diva
Starting Member

9 Posts

Posted - 2007-06-13 : 08:34:35
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
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-13 : 08:40:46
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

22864 Posts

Posted - 2007-06-13 : 08:53:42
<<
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

9 Posts

Posted - 2007-06-14 : 04:34:39
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

22864 Posts

Posted - 2007-06-14 : 08:47:01
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
   

- Advertisement -