Fix Incorrect var in SQL Loop

Fix Incorrect var in SQL Loop