Hi Transistor , i have the dropdown set to bidirectional for all 3 dropdown boxes
have made a named query with this code below
if result_first_day:
first_day_energy = result_first_day[0]["cumulative_energy"]
print("First Day Energy: {}".format(first_day_energy))
else:
first_day_energy = None
print("No first day energy data found.")
query_last_day = """
SELECT cumulative_energy
FROM IgnitionDB.Plants_Cumulative_Energy
WHERE plant_name = ?
AND MONTH(production_date) = ?
AND YEAR(production_date) = ?
ORDER BY production_date DESC
LIMIT 1
"""
print("Executing second query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))
result_last_day = system.db.runPrepQuery(query_last_day, [plant_name, month, year])
if result_last_day:
last_day_energy = result_last_day[0]["cumulative_energy"]
print("Last Day Energy: {}".format(last_day_energy))
else:
last_day_energy = None
print("No last day energy data found.")
if first_day_energy is not None and last_day_energy is not None:
monthly_energy_production = last_day_energy - first_day_energy
print("Monthly energy production for {} in {}/{}: {}".format(plant_name, month, year, monthly_energy_production))
else:
print("Energy data for the specified period is incomplete.")
except Exception as e:
print("An error occurred: {}".format(e))
when i try to execute it i recieve this error message
.
I just need to know if this part has the correct syntax, and how to use the SQL query code in the Script enviroment.
Btw this code works just fine
query = "SELECT * FROM Plants_Cumulative_Energy LIMIT 5"
try:
results = system.db.runQuery(query, "IgnitionDB")
for row in results:
print(row) # Prints each row
except Exception as e:
print("Error fetching data:", str(e))

