January 29, 2019 at 9:56 am
Thom A - Tuesday, January 29, 2019 9:07 AMdrew.allen - Tuesday, January 29, 2019 8:58 AMAs opposed to having to use a dummy value just to trigger the sum to occur? They're not that different.COUNT(CASE WHEN a.Client_ID_Code IS NULL THEN 1 END) AS Null_Count
Also, SUM is more difficult to convert to a DISTINCT COUNT than COUNT is.
COUNT(DISTINCT CASE WHEN <Some Condition> THEN <Some Foreign/Primary Key> END)
I wouldn't even know where to start with a SUM.Drew
You'd need to include CTE or Subquery and ROW_NUMBER most likely. That's going to get messy in my opinion. I agree that COUNT, for a conditional count, makes sense.
Of course if you specifically need COUNT DISTINCT, use it.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing post 16 (of 15 total)
You must be logged in to reply to this topic. Login to reply