# Count Case When statement not allowing me to do arithmetic

**URL:** <https://forum.inductiveautomation.com/t/count-case-when-statement-not-allowing-me-to-do-arithmetic/24036>\
**Category:** General Discussion\
**Tags:** database\
**Created:** [April 11, 2019, 1:09pm UTC](https://forum.inductiveautomation.com/t/count-case-when-statement-not-allowing-me-to-do-arithmetic/24036 "2019-04-11T13:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EEdmondson](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@EEdmondson](https://forum.inductiveautomation.com/u/EEdmondson)\
**Post date:** [April 11, 2019, 1:09pm UTC](https://forum.inductiveautomation.com/t/count-case-when-statement-not-allowing-me-to-do-arithmetic/24036/1 "2019-04-11T13:09:54Z")

</div>

I’m having issues with this section of code:

````auto
	WHEN (HMC_Place_Position = 13 OR 14) AND (Outfeed_Place_Time IS NOT NULL) THEN 1			
END) AS Total_Passed_Remeasures,	```

When I run this code, it gives me the error: "An expression of non-boolean type specified in a context where a condition is expected, near ')'."

I looked up the Case when statement and according to what I found, this should be working.

Here is the rest of my code for reference.

``` SELECT
COUNT(CASE WHEN HMC_Place_Position IS NULL THEN 0 END) AS Parts,

COUNT(*) AS Total_Parts,	

COUNT(CASE
	WHEN Outfeed_Place_Time IS NOT NULL THEN 1		
END) AS Total_Good_Parts, /*Total Good Parts */

(COUNT(Total_Good_Parts)*100 / (Total_Parts)) AS Total_Good_Percent,

COUNT(CASE
	WHEN Reject_Place_Time IS NOT NULL THEN 1 
END) AS Total_Remeasures, /*Total Rejects */

COUNT(CASE
	WHEN (HMC_Place_Position = 13 OR 14) AND (Outfeed_Place_Time IS NOT NULL) THEN 1			
END) AS Total_Passed_Remeasures, /*Total Passed Remeasures */

COUNT(CASE	
	WHEN Outfeed_Place_Time IS NULL THEN 1
END) AS Total_Failed_Remeasures /*Total Failed Rejects */

FROM PartData_GKN05_C
WHERE Infeed_Pick_Time >= DATEADD(day,-7, GETDATE()) 
GROUP BY Total_Parts
ALTER TABLE PartData_GKN05_C Add Total_Passed_Remeasures int
ALTER TABLE PartData_GKN05_C Add Total_Good_Parts int
ALTER TABLE PartData_GKN05_C Add Total_Rejects int
ALTER TABLE PartData_GKN05_C Add Total_Failed_Remeasures int ```
````

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 11, 2019, 1:24pm UTC](https://forum.inductiveautomation.com/t/count-case-when-statement-not-allowing-me-to-do-arithmetic/24036/2 "2019-04-11T13:24:42Z")

</div>

The 13 OR 14 is what’s hosing you over. Try:

`COUNT(CASE WHEN (HMC_Place_Position IN (13, 14)) AND (Outfeed_Place_Time IS NOT NULL) THEN 1 END) AS Total_Passed_Remeasures`

---

<div class="post-metadata">

**Author:** ![EEdmondson](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@EEdmondson](https://forum.inductiveautomation.com/u/EEdmondson)\
**Post date:** [April 11, 2019, 1:39pm UTC](https://forum.inductiveautomation.com/t/count-case-when-statement-not-allowing-me-to-do-arithmetic/24036/3 "2019-04-11T13:39:03Z")

</div>

Thank you! This solved my error! Now to figure out why I’m not getting the right results lol.
