Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have two tables that both hold cpucount information for inventory. I need to run a query that simply gives me a total cpu count from both tables. Both of the following statements work for the sum of each individual table. I just need to get the total of both as in a "Grand Total" of CPU count.Select'Server Total' as CPUtotal, sum (sdw.srvcpucount) as totalFrom server sdw------Select'Unix Total' as CPUtotal, sum (ud.unxcpucount) as totalFrom unix ud
Cyclonik
Posting Yak Master
114 Posts
Posted - 2006-01-24 : 17:13:25
select (select sum (sdw.srvcpucount) From server) + (Select sum(ud.unxcpucount) from unix)) as Grand Total
Cyclonik
Posting Yak Master
114 Posts
Posted - 2006-01-24 : 17:27:44
select sum(total) from (select sum (sdw.srvcpucount) as total From serverUNION ALLSelect sum(ud.unxcpucount) as total from unix) aThis might work too.
SamC
White Water Yakist
3467 Posts
Posted - 2006-01-24 : 17:45:23
And yet another way...
Select sdwTotal, udTotal, sdwTotal + udTotal As GrandTotal FROM ( select (select sum (sdw.srvcpucount) From server) As sdwTotal, (Select sum(ud.unxcpucount) from unix) As udTotal ) X