Hey all,
I am running into a small issue that I am unable to get around at the moment. Right now I am trying to insert values into a tablr in sql but I am hitting the below error. Being that I am new to python coding, I have tried using CAST and CONVERT in my sql script, but none work. Has anyone else hit this issue and been able to get around it? Any insight would be helpful. Thanks. My code and error message are showing below:
I am running into a small issue that I am unable to get around at the moment. Right now I am trying to insert values into a tablr in sql but I am hitting the below error. Being that I am new to python coding, I have tried using CAST and CONVERT in my sql script, but none work. Has anyone else hit this issue and been able to get around it? Any insight would be helpful. Thanks. My code and error message are showing below:
# Client Automation Script import pyodbc import csv cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=ec2-54-80-128-8.compute-1.amazonaws.com;DATABASE=GO_VIV_DMS;UID=UID;PWD=<Secret>') with open('Poland_Test.csv') as csvfile: data = csv.reader(csvfile) cursor = cnxn.cursor() for row in data: cursor.execute('INSERT INTO GO_VIV_DMS.dbo.MasterClient(MasterClientCode,MasterClientDescription,IsActive,IncludeSMIClientPool,IncludeAgencyPool) values(?,?,?,?,?)', row) Print("Done") cursor.close() cnxn.commit()
Error:Error message: Traceback (most recent call last):
File "C:\Users\vwebster\Documents\MISC\Import Automation.py", line 9, in <module>
cursor.execute('INSERT INTO GO_VIV_DMS.dbo.MasterClient(MasterClientCode,MasterClientDescription,IsActive,IncludeSMIClientPool,IncludeAgencyPool) values(?,?,?,?,?)', row)
pyodbc.DataError: ('22018', "[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]
Conversion failed when converting the nvarchar value 'IsActive' to data type bit. (245) (SQLExecDirectW)")