Invalid Column Name When Calculating Initial Variable Value

DECLARE @Total_Good_Percent AS float = ((Total_Good_Parts / Total_Parts)*100)

The above is the function I’m trying to get to work. However, when I run the query it says that “Total_Good_Parts” is an invalid column name. I have declared “Total_Good_Parts” as a column name already. You can see this in my full code snippet below.

SELECT
Count(Case When HMC_Place_Position is null Then 0 end) as Parts,
COUNT(*) AS Total_Parts,																		/*Total Parts */

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

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

COUNT(CASE
	WHEN (Reject_Place_Time IS NOT NULL) 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()) 
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

DECLARE @Total_Good_Percent AS float = ((Total_Good_Parts / Total_Parts)*100)

I believe you will probably need to put this in a stored procedure in your DB and call it from Ignition to get this to work. I think the JDBC drivers have problems with this sort of thing.

1 Like