Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct Count Issue

Status
Not open for further replies.

Whippingboy2004

Technical User
May 19, 2004
16
US
I'm having an issue with a report I'm trying to write in SQL 2000. I'm trying to determine a count for each letter type (NewCert and ReCert, the final report will have about 10 types) AND want to count each Case only once for each letter type.

SELECT DISTINCT(tl.CaseID),
NewCert=CASE tl.TypeCode WHEN 'N2BI' THEN COUNT(DISTINCT tl.TypeCode) ELSE 0 END,
ReCert=CASE tl.TypeCode WHEN 'N3BI' THEN COUNT(DISTINCT tl.TypeCode) ELSE 0 END
FROM TBL_THStepsLetter tl

GROUP BY tl.CaseID, tl.TypeCode
ORDER BY tl.CaseID

This code may be way off, but I've been trying every possible way to get this to work. Any thoughts would be appreciated.

Thanks a bunch,
T.

 
Is this what you want?:

SELECT tl.TypeCode, Count(DISTINCT tl.CaseID) as Cases
FROM TBL_THStepsLetter tl
GROUP BY tl.TypeCode

This will list the Type coded and the number of cases.

I think you may have been complicating the matter.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top