Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyodbc
- import pandas
- ConnectionName = pyodbc.connect('Driver={SQL Server};'
- 'Server=ServerInstanceName;'
- 'Database=DWCountries;'
- 'TrustedConnection=Yes;')
- SqlQuery = "Select * from dbo.DimCountryCode"
- DimCountryCodeDataFrame = pandas.read_sql(SqlQuery, ConnectionName)
- cursor = ConnectionName.cursor()
- for index, row in DimCountryCodeDataFrame.iterrows():
- cursor.execute("INSERT INTO dbo.DimCountryCodeDestination \
- ( \
- [Id], \
- [CountryName], \
- [Alpha2], \
- [Alpha3], \
- [CountryNumericCode], \
- [Iso31662], \
- [RegionName], \
- [SubRegionName], \
- [InterMediateRegionName], \
- [RegionCode], \
- [SubRegionCode], \
- [InterMediateRegionCode] \
- ) \
- values(?,?,?,?,?,?,?,?,?,?,?,?)", \
- row['Id'],
- row['CountryName'],
- row['Alpha2'],
- row['Alpha3'],
- row['CountryNumericCode'],
- row['Iso31662'],
- row['RegionName'],
- row['SubRegionName'],
- row['InterMediateRegionName'],
- row['RegionCode'],
- row['SubRegionCode'],
- row['InterMediateRegionCode'] )
- ConnectionName.commit()
- cursor.close()
- ConnectionName.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement