My table has these info

T123
T153
T174

Basic SQL count works fine which results to (3).. but when I use this function needed for my query the output is 4.

COUNT(DISTINCT CASE WHEN id LIKE '%T%' THEN RIGHT(ID, 3) ELSE 0 END) AS Count

what's wrong with my query,,, im stuck in hours :(

Please help

If you have values that don't contain T then you are adding one to the count by returning to the count the number 0.
You can try to remove else entirely or replace 0 with NULL. I'm guessing both will work.

Can you post a more complete scenario (i.e. more sample data, a complete SQL statement, etc.) to work with? Just with what you've posted I did a little test and it worked fine for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.