Skip to content
Advertisement

Return Dynamic MSSQL query from python

I have this script below. I left out the connection details for security purposes but the code executes with out error in python and in MS SQL 2019

JavaScript

My issue is that this query returns 0 None in python. I need it to return the string I am creating because I intend to use that query going forward. I know the query works it returns correct text when run from MSSQL SSMS.

Advertisement

Answer

I used pyodbc instead of pandas and your code worked for me.

JavaScript

The output:

JavaScript

Here is the table I cobbled for this test case:

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