0

I want to learn python, and my task is the run a sql server 2008 stored procedure via a cron job.

Can someone step through a script for me in python?

mrblah
  • 99,669
  • 140
  • 310
  • 420

1 Answers1

1

I am assuming you mean Microsoft's SQL server...

#! /usr/bin/python

import pymssql
con = pymssql.connect (host='xxxxx',user='xxxx',
                       password='xxxxx',database='xxxxx')
cur = con.cursor()
query = "DECLARE @id INT; EXECUTE sp_GetUserID; SELECT @id;"
cur.execute(query)
outputparameter = cur.fetchall()
con.commit()
con.close()

Taken from http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-10/msg02620.html (copyright retained)

Put that in a script and run it from cron...

Check this question too.

Community
  • 1
  • 1
Ali Afshar
  • 40,967
  • 12
  • 95
  • 109