Skip to content
Advertisement

How to call a complex SQL query in python

I have the following SQL code:

This SQL code has been tested and runs perfectly on SQL Server Management Studio.

Now I have the following code for python which is to communicate with an MS SQL Server instance:

When I run it, I get the following error

where it points to the first semicolon in my code. Could you show me how I may get this python code to run?

Advertisement

Answer

Fixing the quotes and removing the select statement, and I’m pretty sure the last two lines of your SQL got swapped. It should be WHERE…AND, not AND…WHERE. Like this:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement