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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 adding the counts from 2 select statements?

Author  Topic 

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2004-09-02 : 15:54:09
probably something simply but I can't figure it out.

here is the SQL...

AND 6 < (

SELECT count(UserID) FROM hits (NOLOCK) WHERE Company.fkPrimaryContact = hits.UserID AND Sub.fkProduct = 1

-- somehow add the counts from each of these together

SELECT count(UserID) FROM hits_MR (NOLOCK) WHERE Company.fkPrimaryContact = hits_MR.UserID AND (Sub.fkProduct = 2 OR Sub.fkProduct = 8)
)

Thanks,
Craig

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-09-02 : 15:57:48
[code]select max(a) + max(b) as c
from
(
select count(a) a, null b
from ...

union

select null a, count(b) b
from ...

) d[/code]
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2004-09-02 : 16:19:36
Wicked. Works like a charm. Thanks!
Go to Top of Page
   

- Advertisement -