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 2005 Forums
 Transact-SQL (2005)
 Count Function

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-10-24 : 09:43:10
How can I get the total count of all of these tables into one staging table?

I can join on PAN for them all.

SELECT COUNT(PAN) FROM
DryCd1, DryCd2, DryCd3, DryCd4 DryCd5 DryCd6 DryC7

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-24 : 09:45:27
Like this


SELECT COUNT(*) FROM
DryCd1 as t1
inner join DryCd2 as t2 on t1.pan=t2.pan
inner join DryCd3 as t3 on t2.pan=t3.pan
inner join DryCd4 as t4 on t3.pan=t4.pan
.
.



Madhivanan

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

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-10-24 : 09:52:56
This was a little too quick wasn't it Madhi? Here's my take:
SELECT COUNT(*) 
FROM (
SELECT PAN FROM DryCd1 UNION ALL
SELECT PAN FROM DryCd2 UNION ALL
SELECT PAN FROM DryCd3 UNION ALL
SELECT PAN FROM DryCd4 UNION ALL
SELECT PAN FROM DryCd5 UNION ALL
SELECT PAN FROM DryCd6 UNION ALL
SELECT PAN FROM DryCd7) AS dt1


- Lumbago
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-10-24 : 09:53:50
Thanks!
Go to Top of Page
   

- Advertisement -