Skip to content

Instantly share code, notes, and snippets.

Last active August 21, 2022 12:17
What would you like to do?
Extract data from SQL Server:
# get list of history DBs
# note: check permission of the user to access 'master' database
query = "set nocount on; print 'Database';select name from sys.Databases where name like 'History%'"
sqlcmd = f'sqlcmd -S {server} -d ProcessDataDB -U {username} -P {password} -Q "{query}" -s "," -h -1 -W -o "./data/{site}_dbs.csv"'"-- Getting ProcessDataDB History databases...")
# get list of historic databases
df = pd.read_csv(f"./data/{site}_dbs.csv")"Found {len(df.index)} history DBs.\n")
# create list of DBs
list_of_dbs = list(df.Database)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment