I want to call multiple databases in Microsoft SQL:
driver = 'SQL Server'
server = '123'
tcon = 'yes'
uname = 'name'
pword = 'password'
query = "query1"
I make my databases into list as below:
db = ['DBA','DBB','DBC']
Then execute looping to call all databases in the list above as below:
for i in db:
sql_conn = pyodbc.connect(driver='{SQL Server}', host=server, database= f'{i}',
trusted_connection=tcon, user=uname, password=pword)
df = pd.read_sql(query, sql_conn)
df['DB_NAME'] = f'{i}' #to add name column in the dataframe
However, i only get data from 'DBC'. I want three separate dataframes such as df_DBA, df_DBB, df_DBC from the looping above.