📕🐘 도로락 - 코끼리를 냉장고에 넣는 방법
Python | 2019. 4. 11. 16:11

[Python] 파이썬 mssql 쿼리시 Incorrect syntax near .. 20018 오류원인

파이썬 mssql 쿼리시 Incorrect syntax near .. 20018 오류원인

파이썬에서 쿼리시에 다음과 같은 형태로 오류가 난다면 대부분 SQL 문법이나 SQL 리터럴을 유심히 보아야 합니다.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/pythonProject/user/user.py", line 123, in <module>
    mssqlCursor.execute("SELECT * FROM users WHERE Id = %S", "test")
  File "src\pymssql.pyx", line 465, in pymssql.Cursor.execute
pymssql.ProgrammingError: (102, b"Incorrect syntax near 'S'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

WHERE절의 Id 뒤에 파라미터 이스케이프 처리할 때 %s(소문자) 가 되어야 합니다. (%S가 아니라)

mssqlCursor.execute("SELECT * FROM users WHERE Id = %s", "test")
도로락

도로락

Writer

IT, 프로그래밍, 컴퓨터 활용 정보 등을 위한 블로그