Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import pyodbc
  2. import time
  3.  
  4. cnxn1 = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER='Server';DATABASE='DatabaseA';Trusted_Connection=Yes')
  5. cursor1 = cnxn1.cursor()
  6.  
  7. cnxn2 = pyodbc.connect('DRIVER={SQL Server};SERVER='Server', user='Username', password='Password', database='DatabaseB')
  8. cursor2 = cnxn2.cursor()
  9. SQL = cursor1.execute("select * from table.DatabaseA")
  10. SQL2 = """insert into table.DatabaseB([col1], [col2], [col3],[col4], [col5], [col6], [col7], [col8], [col9], [col10], [col11], [col12], [col13], [col14], [col15], [col16],[col17], [col18], [col19], [col20], [col21], [col22], [col23], [col24], [col25], [col26], [col27], [col28], [col29], [col30], [col31]) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"""
  11.  
  12. for row in cursor1.fetchall():
  13. cursor2.execute(SQL2,row)
  14.  
  15. `for row in SQL:
  16. cursor2.execute(SQL2,row)`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement