I am using Pyodbc to pull some data off our internal database, and am using the following SQL which works perfectly in SQL Server Management Studio.
'SELECT GrantInformation.GrantRefNumber, Count(GrantResearchTopic.PrimaryInd) AS CountOfPrimaryInd
FROM GrantInformation
LEFT JOIN GrantResearchTopic ON GrantInformation.GrantRefNumber = GrantResearchTopic.GrantRefNumber
WHERE ((GrantResearchTopic.PrimaryInd)='True')
GROUP BY GrantInformation.GrantRefNumber;'
For some reason if I remove the WHERE statement the SQL pull works, but if I leave it in, I get 'INVALID SYNTAX' despite as I said the SQL working fine in SQLSMS.
I have tried using double quotes around true, but get the following error:
ProgrammingError: ('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'True'. (207) (SQLExecDirectW)")
Any ideas?
Edit: Problem solved. I didn't use double quotes on my SQL Statement so it wouldn't recognise the single quotes around the True statement. Using 1 worked as wasnt using quote marks, and using double quotes around the statement also worked as it then recognised the single quotes around 'True'. Thank you all.