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
 Add two value

Author  Topic 

atulbharadwaj
Starting Member

11 Posts

Posted - 2009-12-15 : 00:21:01
hi, can someone add result of two sql statement through procedure

select Max(sep) as Sep1 from pricescore
select Max(sep) as Sep from Earningscore

i need result = Sep1 + Sep



atul

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-15 : 01:32:58
select sep1+sep as result
from (
select Max(sep) as Sep1 from pricescore union all
select Max(sep) as Sep from Earningscore) t

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-15 : 02:03:15
or

select
(select Max(sep) as Sep1 from pricescore)
+
(select Max(sep) as Sep from Earningscore)


Madhivanan

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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-15 : 02:05:22
or the long way:

DECLARE @v1 int, @v2 int, @v3 int

select @v1 = Max(sep) as Sep1 from pricescore
select @v2 = Max(sep) as Sep from Earningscore

set @v3 = @v1 + @v2 or just select @v1 + @v2

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -