I have a problem using backslashes with ' in a query launched in python. This is the query:
c.execute("SELECT Num FROM Table WHERE cie = 'TAB_' AND tablecode = 'IDL\DOC\'TAB_'\'{G}'\'FV'\' ' ' ".format(G=date.today().year))
the problem is that even if I do something like this :
c.execute("SELECT Num FROM Table WHERE cie = 'TAB_' AND tablecode = 'IDL\\DOC\\'TAB_'\\'{G}'\\'FV'\\' ' ' ".format(G=date.today().year))
it gives me the same error:
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'TAB_'. (102) (SQLExecDirectW)")
My field in sql contains values like this : VALUE1\VALUE2'VALUE3'\' ' So I have to use backslashes How can I do it?