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.
| Author |
Topic |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2010-10-26 : 08:37:16
|
| This is my query which works fine:select UserName,ReportID,ReportCount,PeriodKey,b.BUKey,c.TerritoryName from F_BIUsers_Reports a inner join D_BIUsers b on a.UserKey = b.UserKey inner join D_BusinessUnits c on b.BUKey = c.BUKeywhere PeriodKey =94 and c.Year = 2010order by ReportCount descI now want to count the number of records which this query generates and have tried the following (without success)count (*) from (select UserName,ReportID,ReportCount,PeriodKey,b.BUKey,c.TerritoryName from F_BIUsers_Reports a inner join D_BIUsers b on a.UserKey = b.UserKey inner join D_BusinessUnits c on b.BUKey = c.BUKeywhere PeriodKey =94 and c.Year = 2010order by ReportCount desc)Many thanks for your help on this |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-10-26 : 08:51:25
|
SELECT count (*) from (select 1 UserName,ReportID,ReportCount,PeriodKey,b.BUKey,c.TerritoryNamefrom F_BIUsers_Reports a inner join D_BIUsers b on a.UserKey = b.UserKey inner join D_BusinessUnits c on b.BUKey = c.BUKeywhere PeriodKey =94 and c.Year = 2010order by ReportCount desc) AS XOr add this immediately after the first query:SELECT @@ROWCOUNT AS MyCountOr change to become:SELECT count (*)from F_BIUsers_Reports a inner join D_BIUsers b on a.UserKey = b.UserKey inner join D_BusinessUnits c on b.BUKey = c.BUKeywhere PeriodKey =94 and c.Year = 2010 |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2010-10-26 : 10:00:35
|
| Thank you Tristan, that is extremely helpful. thanks |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2010-10-26 : 10:09:10
|
| Sorry, its Kristen :) |
 |
|
|
|
|
|
|
|