# Import arcpy module import arcpy import pyodbc import os # Set Geoprocessing environments arcpy.env.overwriteOutput = True DatabaseConnectionString = "Driver={SQL Server Native Client 10.0};SERVER=myserver;DATABASE=mydatabase;Trusted_Connection=yes" LocationsForGISProcessing = "dbo.vw_myview" ScratchGeodatabasePath = "E:\\Workspace\\Warehouse\\ScratchWorkspace\\Scratch.gdb" TempLocationsForGISProcessing = "LocationsForGISProcessing" ##################################################################################### # Create ODBC connection conn = pyodbc.connect(DatabaseConnectionString) cursor = conn.cursor() print "Connected to database" ################################################################################## # Insert the data into the geodatabase TempTable = ScratchGeodatabasePath + "\\" + TempLocationsForGISProcessing # Process: Delete Rows From Previous Load arcpy.DeleteRows_management(TempTable) arcpyCursor = arcpy.InsertCursor(TempTable) cursor.execute("SELECT * FROM " + LocationsForGISProcessing) rows = cursor.fetchall() for row in rows: arcpyRow = arcpyCursor.newRow() arcpyRow.Location_Key = row.Location_Key arcpyRow.From_Date = row.From_Date arcpyRow.XCoord = row.XCoord arcpyRow.YCoord = row.YCoord arcpyCursor.insertRow(arcpyRow) # Delete the arcypy cursor del arcpyCursor # Close the connection if (cursor is not None): cursor.close() del cursor if (conn is not None): conn.close() del conn
Solved! Go to Solution.
# convert the sqlserver type from numeric to float arcpyRow.XCoord = float(row.XCoord)
# or maybe attempt to use a variable if the above fails xval = float(row.XCoord) arcpyRow.XCoord = xval
# convert the sqlserver type from numeric to float arcpyRow.XCoord = float(row.XCoord)
# or maybe attempt to use a variable if the above fails xval = float(row.XCoord) arcpyRow.XCoord = xval
James,
That did it!
Thank you so much!
Darina