Python SQL Select with possible NULL values
null, python, sql
Solution
If you are using SQL Server then as long as you set ANSI_NULLS off for the session '= null' comparison will work.
SET ANSI_NULLS
Problem
I'm new to python and have hit a problem with an SQL query I'm trying to perform. I am creating an SQL SELECT statement that is populated with values from an array as follows: ``` ret = conn.execute('SELECT * FROM TestTable WHERE a = ? b = ? c = ?', *values) ``` This works ok where I have real values in the values array. However in some cases an individual entry in values may be set to None. The query then fails because the "= NULL" test does not work since the test should be IS NULL. Is there an easy way around this?