import urllib
import sqlalchemy
import pandas as pd
sql_query = 'SELECT * FROM <tabl-name>'
server = '<sql-server-hostname>'
database = '<sql-server-name>'
username = '<login-id>'
password = '<password>'
driver = '{ODBC Driver 17 for SQL Server}'
odbc_str = 'DRIVER='+driver+';SERVER='+server+';PORT=1433;UID='+username+';DATABASE='+ database + ';PWD='+ password
connect_str = 'mssql+pyodbc:///?odbc_connect=' + urllib.parse.quote_plus(odbc_str)
engine = sqlalchemy.create_engine(connect_str)
df = pd.read_sql(sql_query, engine)
print(df)
Thanks for reading and happy learning!
billy-at-
python.sg