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
 How to add two values of 2 computed columns?

Author  Topic 

HeyZain
Starting Member

7 Posts

Posted - 2010-02-04 : 00:39:22
Hi folks,

Could somebody guide me with example how can i add the values of two computed columns to make a third computed column?

I am using SQL Server 2005 dev. edition.

Thanks & Regards,
Zain.

Z@in

binto
Yak Posting Veteran

59 Posts

Posted - 2010-02-04 : 01:03:08
Try this

DECLARE @T TABLE (value int,rate int)

INSERT @T
SELECT 3,6
UNION ALL SELECT 5,6
UNION ALL SELECT 7,34
UNION ALL SELECT 9,23
UNION ALL SELECT 23,22
UNION ALL SELECT 22,12
UNION ALL SELECT 18,32
UNION ALL SELECT 34,43

SELECT value,rate, (value+rate) as result FROM @T

Thanks & Regards
Binto Thomas
Go to Top of Page

HeyZain
Starting Member

7 Posts

Posted - 2010-02-04 : 02:22:37
Thanks a lot binto.. Exactly what i needed. :)

Z@in
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-04 : 03:15:14
if you want to perform operations b/w two computed columns, it should be
SELECT c,d,c*100.0/d
FROM
(
SELECT a,b, (a + b) as c, (a- b) as d
FROM table
)t
Go to Top of Page
   

- Advertisement -