I am using pypyodbc to pull data but I will simplify the data for this example. My issue is that I have a column named 475Election and when I pull data from this column I am getting 475 as a value in python. For example:
TradeID ...Other Values... 475Election
1 ...Other Values... 0
But when I use python I am getting the output
1 ...Other Values... 475.0
I believe that this may be a result of an error in datatype or maybe with pypyodbc or just as a SQL problem in general. Also when I query this information in SQL it is returning the proper value. 475Election is a bit datatype.
EDIT* Code in python
cursor = connection.cursor()
SQLCommand = "SELECT * FROM dbo.Trade"
cursor.execute(SQLCommand)
column_names = [d[0] for d in cursor.description]
try:
column_names.remove('ssma_timestamp')
except ValueError:
pass
SQLCommand = "SELECT " + ', '.join(column_names) + " FROM dbo.Trade"
cursor.execute(SQLCommand)
vals = cursor.fetchall()
SQLCommand_steve = "INSERT INTO dbo.Trade (" + ', '.join(column_names) + ") VALUES (" + ','.join('?' * len(column_names)) + ")"
print SQLCommand_steve
print vals
cursor_steve.executemany(SQLCommand_steve, vals)
connection_steve.commit()
connection_steve.close()
connection.close()
print 'done'
Output:
INSERT INTO dbo.Trade (tradeid, *redacted column names for compliance*, 475election) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
53, u'1', u'2016-01-26 10:11:55', *Redacted, *Redacted, True, *Redacted, *Redacted, False, False, None, None, None, 475.0
Real value for the last printed value is the 475election column, and should be 0. I am using Microsoft SQL Server Express (64bit), the OS is Microsoft Windows NT 6.1. The version is 12.0.4422.0