I need to convert a big SQL code in python. Instead of converting SQL code to python, Is there any way we can run sql query in python Script? Let's suppose there is a stored procedure in my MsSqlServer. How can I call that stored procedure in python?
A way could be the following (you could save the whole query which will of course be more complicated than the one in the example):
# Import sqlalchemy's create_engine() function
from sqlalchemy import create_engine
import pandas as pd
# Create the database engine
engine = create_engine("mssql+pyodbc://user:pass@dsn")
# Create a SQL query to load the entire table
query = """
SELECT *
FROM XXX;
"""
# Load with the SQL query
load = pd.read_sql(query, engine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With