sum the values more querys

Posted by Sekar.C under Sql Server on 3/27/2012 | Points: 10 | Views : 856 | Status : [Member] | Replies : 2
hi,
how to get sum value in this code
select max(iscore) from hospitals where flatid='F001'
union all
select max(iscore) from Restaurants where flatid='F001'
union all
select max(iscore) from Transports where flatid='F001'
union all
select max(iscore) from Markets where flatid='F001'


Regards
Sekar.c



Responses

Posted by: Sksamantaray on: 3/27/2012 [Member] Silver | Points: 25

Up
0
Down
Hi ,
instead of union use temporary table.

insert into #temp
select max(iscore) score from hospitals where flatid='F001'
insert into #temp
select max(iscore) score from Restaurants where flatid='F001'
insert into #temp
select max(iscore) score from Transports where flatid='F001'
insert into #temp
select max(iscore) score from Markets where flatid='F001'
select SUM(score) from #temp
drop table #temp


Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/28/2012 [Member] Bronze | Points: 25

Up
0
Down
You can also get by using following query,

select sum(iscore) from (
select max(iscore) from hospitals where flatid='F001'
union all
select max(iscore) from Restaurants where flatid='F001'
union all
select max(iscore) from Transports where flatid='F001'
union all
select max(iscore) from Markets where flatid='F001') temp

Thanks,
Rajni Shekhar

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response