Skip to content

Instantly share code, notes, and snippets.

@gdevanla
Created May 19, 2016 16:15
Show Gist options
  • Save gdevanla/65a02b51427f9f885c934c23a3cfc43a to your computer and use it in GitHub Desktop.
Save gdevanla/65a02b51427f9f885c934c23a3cfc43a to your computer and use it in GitHub Desktop.
import pyodbc
# This will be the query to run
sql = 'SELECT * FROM AAF_IS_USER'
# conn_str = Here repace USER with treussard and YOUR_PASSWORD with the actual password
conn_str = "DRIVER={FreeTDS};DSN=irv_sql02;UID=ra\treussard;PWD=YOUR_PASSWORD;DATABASE=AAF;"
# connecting to the database
conn = pyodbc.connect(conn_str)
# Run the query. This will fetch a cursor
c = conn.execute(sql)
# Loop through all the records and print the records
for r in c.fetchall():
# print comma separated list of fields from each row
print(",".join([str(i) for i in r]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment