# Invalid Column Name When Calculating Initial Variable Value

**URL:** <https://forum.inductiveautomation.com/t/invalid-column-name-when-calculating-initial-variable-value/23853>\
**Category:** Ignition\
**Created:** [April 4, 2019, 3:24pm UTC](https://forum.inductiveautomation.com/t/invalid-column-name-when-calculating-initial-variable-value/23853 "2019-04-04T15:24:46Z")\
**Posts on this page:** 2\
**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 4, 2019, 3:24pm UTC](https://forum.inductiveautomation.com/t/invalid-column-name-when-calculating-initial-variable-value/23853/1 "2019-04-04T15:24:46Z")

</div>

```auto
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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 4, 2019, 3:29pm UTC](https://forum.inductiveautomation.com/t/invalid-column-name-when-calculating-initial-variable-value/23853/2 "2019-04-04T15:29:19Z")

</div>

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.
