1

I have the below query that Python uses to insert values into database.

INSERT INTO Shift_Info (Login_Date,Machine_Number,Item_Number,Job_Number,Operator,Shift,LogOff_Date,Good_Parts,Total_Run_Time,Effective_Run_Time,Run_Through) 
VALUES (2020-03-16 15:42:21,'CX07',310164,5165877,21952,1,2020-03-16 15:51:06,89,525,525,12)

But get the below error on the first entry of time value at '15'. Whats the issue and any solution other than reformatting inputs?

pypyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '15'.")

2

1 Answer 1

2

After reading the docs on transact-sql https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-ver15

I just need to enclose in quotes to allow SQL Server to parse the string.

INSERT INTO Shift_Info (Login_Date,Machine_Number,Item_Number,Job_Number,Operator,Shift,LogOff_Date,Good_Parts,Total_Run_Time,Effective_Run_Time,Run_Through) 
VALUES ('2020-03-16 15:42:21','CX07',310164,5165877,21952,1,'2020-03-16 15:51:06',89,525,525,12)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.