Python und der Sqlserver

Es gibt ein Python Modul für den Zugriff auf den MS Sqlserver: pymssql. Hier ein Skript, das die Id und ein Datum aus einer Tabelle selektiert und ausgibt:

con = pymssql.connect(host=”hostname,user=’name’,password=’kennwort’,database=’dbname’)
cur = con.cursor()
query=”select id,datum from tabelle where datum>=\’” + von + “\’ and ts_insert<=\’” + bis + “\’”
cur.execute(query)
for row in cur.fetchall():
  id = row[0]
  datum = row[1]
  print Id + ” vom ” + str(datum.day) + “.” + str(datum.month) + “.” + str(datum.year) + ” um ” + str(datum.hour) + “:” + str(datum.minute) + “:” + str(datum.second)
con.commit()
con.close()

Ich benutze das Modul zur einfachen Auswertung von Cronjobs, die jede Nacht laufen und Fehler in einer Datenbanktabelle protokollieren.

Sags in Deinen Worten.