Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import csv
  2. import datetime
  3. import pyodbc
  4. import MySQLdb
  5.  
  6. start = datetime.date.today()
  7. close = start + datetime.timedelta(days = 2)
  8.  
  9. conn = pyodbc.connect(
  10. r'DRIVER={ODBC Driver 11 for SQL Server};'
  11. r'SERVER=ncs-dr01;'
  12. r'DATABASE=zcus;'
  13. r'UID=board;'
  14. r'PWD=****************'
  15. )
  16. db = MySQLdb.connect(host= "localhost",
  17. user= "admin",
  18. passwd= "**************",
  19. db = "boards",) # name of the data base
  20.  
  21. cursor = conn.cursor()
  22. query = """ SELECT OperationDateTime, OperationID,
  23. (SELECT id
  24. FROM [db].[objects].[adm_surgeon_color] as SC
  25. WHERE surgeon_mnemonic = SurgeonID), Name
  26. FROM SCH_OR
  27. WHERE OperationDateTime > ? AND OperationDateTime < ? """
  28.  
  29. cursor.execute(query,(start,close,))
  30.  
  31. #write query results to csv and pack
  32. #need to add step to convert SurgeonID to suregon_color.id
  33. with open("dailypatientlist2.csv", "w") as outfile:
  34. writer = csv.writer(outfile,lineterminator="\n")
  35. for row in cursor:
  36. writer.writerow((row))
  37.  
  38.  
  39.  
  40. #close
  41. cursor.close()
  42. conn.close()
  43. db.close
  44.  
  45. --------------------------------
  46. Traceback (most recent call last):
  47. File "extract2.py", line 29, in <module>
  48. cursor.execute(query,(start,close,))
  49. pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 11 for SQL S
  50. erver][SQL Server]Invalid object name 'db.objects.adm_surgeon_color'. (208) (SQL
  51. ExecDirectW)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement