SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: UNION ALL Count Query
-
May 2, 2008, 07:04 #1
- Join Date
- Oct 2006
- Posts
- 408
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
UNION ALL Count Query
Hi,
How I want to get the total count from the below queries and add them together.
How do I do this?
The first part of the UNION cluase returns 4
the next part returns 1
But I want to only return 5.
Is this possible?
Thanks.
Code:SELECT DISTINCT COUNT(p.Portfolio) AS FundTotal FROM Staff AS s INNER JOIN Portfolio AS p ON p.PortfolioID = s.FundID WHERE (s.Name = @Name) UNION ALL SELECT DISTINCT COUNT(FundID) AS FundTotal FROM Access AS a WHERE (Name = @Name) AND (SelDate = @Date)
-
May 2, 2008, 07:13 #2
- Join Date
- Jan 2004
- Location
- Uppsala, sverige
- Posts
- 700
- Mentioned
- 2 Post(s)
- Tagged
- 1 Thread(s)
Code:select sum(fundtotal) as s from ( SELECT COUNT(p.Portfolio) AS FundTotal FROM Staff AS s INNER JOIN Portfolio AS p ON p.PortfolioID = s.FundID WHERE s.Name = @Name UNION ALL SELECT COUNT(FundID) FROM Access AS a WHERE Name = @Name AND SelDate = @Date) dt
-
May 2, 2008, 07:35 #3
- Join Date
- Oct 2006
- Posts
- 408
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks!
What does the dt at the end mean?
-
May 2, 2008, 08:01 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
May 2, 2008, 08:35 #5
- Join Date
- Oct 2006
- Posts
- 408
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks!
Bookmarks