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
 Totals in Query from two tables

Author  Topic 

cloudy007
Starting Member

1 Post

Posted - 2007-06-05 : 08:29:00
Hi all,

I hope someone can help me with this problem, cos I'm a bit lost.

We have a system and its needs to check whether an employee is assigned to a Group or not. With one table, its not a problem.

Select Count(CardID) from Table Where GroupID is Null.

Now we created a different table for different Employees.

I basically need to do the following
Select Count(CardID) as HRCount from Table1 Where etc, etc
Select Count(CardID) as FPCount From Table2 Where etc, etc

However I need ONE total, if possible at once.

There is no relation between the tables.

To SUM it up, I need ONE total from TWO separate tables.

Is it possible?

Thanks and Regards

Claudio

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-05 : 08:31:39
selcet * from
(Select count1 = Count(CardID) as HRCount from Table1 Where etc, etc) a
cross join
(Select count2 = Count(CardID) as FPCount From Table2 Where etc, etc) b

or

Select count1 = Count(CardID) as HRCount from Table1 Where etc, etc
union all
Select Count(CardID) as FPCount From Table2 Where etc, etc

or

select sum(count1) from
(Select count1 = Count(CardID) as HRCount from Table1 Where etc, etc
union all
(Select count2 = Count(CardID) as FPCount From Table2 Where etc, etc) a


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-05 : 08:34:59
Select sum(HRCount ) from
(
Select Count(CardID) as HRCount from Table1 Where etc, etc
union all
Select Count(CardID) From Table2 Where etc, etc
) s

--------------------------------------------------
S.Ahamed
Go to Top of Page
   

- Advertisement -