Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyodbc
- import time
- cnxn1 = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER='Server';DATABASE='DatabaseA';Trusted_Connection=Yes')
- cursor1 = cnxn1.cursor()
- cnxn2 = pyodbc.connect('DRIVER={SQL Server};SERVER='Server', user='Username', password='Password', database='DatabaseB')
- cursor2 = cnxn2.cursor()
- SQL = cursor1.execute("select * from table.DatabaseA")
- 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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"""
- for row in cursor1.fetchall():
- cursor2.execute(SQL2,row)
- `for row in SQL:
- cursor2.execute(SQL2,row)`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement