I am trying to use a variable with pymssql to retrieve a database query in 2.7 Python. I run into a syntax error when trying to run the script. The script is below:
school = 'Some School'
sql_statement = '''
SELECT TOP 10
a.Item_Name,
sum(a.Sales) 'Total_Spend'
FROM some_DB a
WHERE
a.School_Name = {}
GROUP BY a.Health_Rating, a.Item_Name
ORDER BY 2 DESC;
'''.format(school)
There is no problem with the connection, so I have excluded that code.
It only errors when I try to add the variable using the .format() method. Any help into this would be greatly appreciated.
Cheers.