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.
Author |
Topic |
diva
Starting Member
9 Posts |
Posted - 2007-06-12 : 09:34:20
|
Hi Allcould someone please advise how i would write my SQL codeso that it woould add the contents of two colums togetherIE column J = 111.50 & column K = 256.30 then column N = 367.80thanks |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-12 : 09:38:45
|
[code]Select (colA + ColB) as ColCFrom SomeTable[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
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?MadhivananFailing to plan is Planning to fail |
|
|
diva
Starting Member
9 Posts |
Posted - 2007-06-12 : 10:05:14
|
thank you very much I will try this |
|
|
diva
Starting Member
9 Posts |
Posted - 2007-06-13 : 08:34:35
|
Hi AllI have tried the above by writing the followingupdate RN_20000718115255CounterParty1select ("option_price" + "Commission") as RN_20000718115255CounterParty1.[25] from RN_20000718115255CounterParty1however it does not work. could you please advise what i have done wrongthanksDiva |
|
|
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_20000718115255CounterParty1SET SomeCol = Coalesce(option_price, 0.00) + Coalesce(Commission, 0.00)Where <some-optional-condition> Note: Replace SomeCol with actual column nameHarsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
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? MadhivananFailing to plan is Planning to fail |
|
|
diva
Starting Member
9 Posts |
Posted - 2007-06-14 : 04:34:39
|
I want to add the values together in Column Option_Price & Commissionso if in Option_Price it is 10 & in commission it is 12 the value in column 20 will be 32Diva |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|