I have a .sql script.
The script first checks function existence, then create a function if not exist.
It then declares variables.
Finally, it executes a query.
The script can produce correct result when executing in sql server management studio.
I used pandas to read the table:
with open('query.sql', 'r') as f:
query = f.read()
df = pd.read_sql_query(query, conn_str)
But it returns
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near \'GO\'. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]\'CREATE FUNCTION\' must be the first statement in a query batch. (111); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the scalar variable "@number". (137); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]A RETURN statement with a return value cannot be used in this context. (178); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near \'GO\'. (102)')
What can I do?