• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

COUNT OR SUM WITH CONDITION

Hi All,

I try below code :

SELECT
SecCode
, SUM(CASE WHEN ISNULL(MemberOf, '') <> '' THEN 1 ELSE 0 END) AS Member
, SUM(CASE WHEN ISNULL(MemberOf, '') = '' THEN 0 ELSE 1 END) AS NonMember
FROM TMEMPLOYEE
WHERE ResignDate Is NULL
GROUP BY SecCode
ORDER BY SecCode

Both Member and NonMember have same number result, this is wrong query.

What should I do  ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
1 Solution
 
LIONKINGCommented:
Try this:

SELECT
SecCode
, SUM(CASE WHEN ISNULL(MemberOf, '') != '' THEN 1 ELSE 0 END) AS Member
, SUM(CASE WHEN ISNULL(MemberOf, '') = '' THEN 1 ELSE 0 END) AS NonMember
FROM TMEMPLOYEE
WHERE ResignDate Is NULL
GROUP BY SecCode
ORDER BY SecCode
0
 
emi_sastraAuthor Commented:
Great.

Thank you very much for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now