I am trying to insert into a Microsoft SQL Server database using the Microsoft ODBC 11 SQL Driver for Linux from a python program using pyodbc. (That's a mouthful) So I have tested the connect, the subquery, and using dateadd in separate queries. Those all work, but when I try to put them all together into this insert statement I get a syntax error at the second to last ')' on the second to last line. What am I missing here?
cursor.execute("INSERT INTO room_use_log VALUES ("+
"(SELECT bldg_flr_spc_id FROM bldg_flr_spc WHERE rm_atl_nbr="+
rooms[y]["Name"] +"),'t','f',dateadd(ms,"+
str(int(str(r.get(rooms[y]["Name"]))[1:])) +", '1970-01-01'),"+
" dateadd(ms,"+
str(int(time.time())) +
", '1970-01-01')" #<----that one
)
This is the entire error:
Traceback (most recent call last):
File "DBGetRedis.py", line 59, in <module>
", '1970-01-01')"
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 11 for SQL Server]
[SQL Server]Incorrect syntax near ')'. (102) (SQLExecDirectW)")