Question: How do you count distinct rows in a query?
1st Try: I *thought* this would work:
select distinct count(taskid) from #temp
however, it returned the count of all taskid's.
2nd Try: then I tried keeping duplicates out to begin with, so I could just do a normal count(taskid). That wasn't fool proof.
Solution: Just out of the “what-would-happen-if-I-did-this” department:
select count(distinct taskid) from #temp
Looks totaly wrong, but it worked!??! Althought I have never heard or seen this done, I am sure people will show me up by telling me how it is “all over Books Online” and such. Whatever, for now, I “invented” it.













2 Responses
+
#