Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import pyodbc
  2. import pandas
  3.  
  4. ConnectionName = pyodbc.connect('Driver={SQL Server};'
  5. 'Server=ServerInstanceName;'
  6. 'Database=DWCountries;'
  7. 'TrustedConnection=Yes;')
  8.  
  9. SqlQuery = "Select * from dbo.DimCountryCode"
  10. DimCountryCodeDataFrame = pandas.read_sql(SqlQuery, ConnectionName)
  11. cursor = ConnectionName.cursor()
  12.  
  13. for index, row in DimCountryCodeDataFrame.iterrows():
  14. cursor.execute("INSERT INTO dbo.DimCountryCodeDestination \
  15. ( \
  16. [Id], \
  17. [CountryName], \
  18. [Alpha2], \
  19. [Alpha3], \
  20. [CountryNumericCode], \
  21. [Iso31662], \
  22. [RegionName], \
  23. [SubRegionName], \
  24. [InterMediateRegionName], \
  25. [RegionCode], \
  26. [SubRegionCode], \
  27. [InterMediateRegionCode] \
  28. ) \
  29. values(?,?,?,?,?,?,?,?,?,?,?,?)", \
  30. row['Id'],
  31. row['CountryName'],
  32. row['Alpha2'],
  33. row['Alpha3'],
  34. row['CountryNumericCode'],
  35. row['Iso31662'],
  36. row['RegionName'],
  37. row['SubRegionName'],
  38. row['InterMediateRegionName'],
  39. row['RegionCode'],
  40. row['SubRegionCode'],
  41. row['InterMediateRegionCode'] )
  42.  
  43. ConnectionName.commit()
  44. cursor.close()
  45. ConnectionName.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement