Thursday, March 22, 2012

Count (Distinct ?

Count(Distinct col1) only works with one column. What you can do is
something like this:
insert @.Table values('Jeff', 'Jones')
insert @.Table values('Jeff', 'Jones')
insert @.Table values('Jeff', 'James')
insert @.Table values('Ed', 'James')
insert @.Table values('Ed', 'James')
select Count (Distinct FName+'|'+LName)
from @.Table
Note that the I just didn't concatenate Fname and Lname because 'Tom' +
'aster' is not the same at 'To' + 'Master'> select Count (Distinct FName+'|'+LName)
Careful, make sure neither is NULLable.

No comments:

Post a Comment