How to do a case sensitive GROUP BY?

Posted by Abe Miessler on Stack Overflow See other posts from Stack Overflow or by Abe Miessler
Published on 2012-06-08T16:30:50Z Indexed on 2012/06/08 16:40 UTC
Read the original article Hit count: 200

If I execute the code below:

with temp as
(
  select 'Test' as name
  UNION ALL
  select 'TEST'
  UNION ALL
  select 'test'
  UNION ALL
  select 'tester'
  UNION ALL
  select 'tester'
)
SELECT name, COUNT(name)
FROM temp
group by name

It returns the results:

TEST   3
tester 2

Is there a way to have the group by be case sensitive so that the results would be:

Test   1
TEST   1
test   1
tester 2

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server