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
 sum data in two columns

Author  Topic 

diva
Starting Member

9 Posts

Posted - 2007-07-24 : 05:54:17
Hi All

Please can someone help me
I Have a problem whereby I cannot get the contents of two columns to add together

my code is
update RN_20000718115255CounterParty1set[RN_20000718115255CounterParty1].[19] =
([RN_20000718115255CounterParty1].[19]) + ([RN_20000718115255CounterParty1].[17])
could someone please advise where i have gone wrong

thanks & regards

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-24 : 05:56:08
is there an error you get or worng sums or what?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 06:05:34
You need spacing before and after the SET

UPDATE 	RN_20000718115255CounterParty1
SET [RN_20000718115255CounterParty1].[19] = [RN_20000718115255CounterParty1].[19] +
[RN_20000718115255CounterParty1].[17]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

diva
Starting Member

9 Posts

Posted - 2007-07-24 : 06:07:14
Thanks ever so much that has worked a treat

Go to Top of Page

diva
Starting Member

9 Posts

Posted - 2007-07-24 : 07:03:12
Thanks for the reply however when i run the query
it appears not to be summing the two amounts together but just
concatenating them ie: in column 17 I have 57.00 & column 19 i have
2.00 I want it to display 59.00

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 07:15:38
your column must be a varchar not integer.
use convert() function to convert to integer or decimal, perform you addition then convert back to varchar()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

diva
Starting Member

9 Posts

Posted - 2007-07-24 : 07:42:12
Thanks for your reply but i am not sure how to do this

Extremely sorry
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 07:54:03
[code]UPDATE RN_20000718115255CounterParty1
SET [RN_20000718115255CounterParty1].[19] = CONVERT(varchar(10),
CONVERT(decimal(10,2), [RN_20000718115255CounterParty1].[19]) +
CONVERT(decimal(10,2), [RN_20000718115255CounterParty1].[17])
)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

diva
Starting Member

9 Posts

Posted - 2007-07-24 : 07:56:25
that is absolutly fantastic it is just what i need
thanks very very much

Go to Top of Page
   

- Advertisement -