Count Case When statement not allowing me to do arithmetic

database
#1

I’m having issues with this section of code:

	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 ```
1 Like

#2

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

1 Like

#3

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

1 Like