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)
 Calculate on field out of many

Author  Topic 

kdeutsch
Yak Posting Veteran

83 Posts

Posted - 2009-11-09 : 10:57:39
I have a table where a person can have multiple personnel problems but I only want to count one of the records that is in a critical status, no more. so if a person has 10 critical tasks the count would be one against them and not 10. here is my current count and it bring s up 14 as the count, but that is not correct and should only bring up 5 becasue there are 5 people assigned but they each have multiple critical tasks.


Select distinct Count(pt.strTaskName),
pt.strSSN,
pt.strname
from tblpermTask as pt INNER JOIN
tblFilter as f on f.intFilterID = pt.intFilterID INNER JOIN
tblUnitPersonnel as up on up.strSSN = pt.strSSN INNER JOIN
tblUnitPosition as p on p.intPositionId = up.intPositionID
where f.strPriority = 'Critical' and p.intUnitMObID = 458 and pt.dtCompleted IS NULL
Group by pt.strSSN, pt.strname

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-09 : 11:01:05
try

Select Count(distinct pt.strname),...
Go to Top of Page
   

- Advertisement -