Current code:
import pyodbc
connection = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
if connection:
print("Yes we connected\n")
cur = connection.cursor()
cur.execute(SELECT cost1 FROM tbl)
data = cur.fetchall()
for row in data:
print(row)
I admit I have almost no idea what I am doing in python and I got slapped with a project a little while ago that is do ASA-yesterday. I need to be able to take the results from the SQL query and sum them together. Or store them in variables to where I can call back to them in an equation.
Results are: 10, 431, 543, 1268, 1207
Expected Result: 3459
I am more than happy to give any more information, and I will be spending the interim continuing to research.
datais a list which contains numbers, row is just one of those numbers so you can't usesum(row). You can add row values to a variable one-by-one but you can usesumfunction fordata