這是我發送的查詢:
SELECT "*" FROM "tkscale" WHERE "UfText1" IN ("12","23","45","0");
但我收到以下錯誤。
錯誤 (pymssql._pymssql.ProgrammingError) (207, b"無效的列名 '0'.DB-Lib 錯誤訊息 20018,嚴重性 16:\n一般 SQL Server 錯誤:檢查來自 SQL Server 的訊息\nDB-Lib 錯誤訊息 20018,嚴重性 16:\n一般 SQL Server 錯誤:檢查來自 SQL Server 的訊息\nDB-Lib 錯誤訊息 20018,嚴重性 16:\n一般 SQL Server 錯誤:檢查來自 SQL Server 的訊息\nDB-Lib 錯誤訊息 20018,嚴重性 16:\ n常規 SQL Server 錯誤:檢查來自 SQL Server 的訊息\nDB-Lib 錯誤訊息 20018,嚴重性 16:\n常規 SQL Server 錯誤:檢查來自 SQL Server 的訊息\n")
我創建這樣的查詢:
table="tkscale",
cols="*",
where="UfText1",
ids=[12, 23, 45, 0]
SELECT_QUERY = "SELECT {cols} FROM {table} WHERE {where} IN ({ids});"
query = SELECT_QUERY.format(
table='"{}"'.format(table),
where='"{}"'.format(where),
ids=",".join(['"{}"'.format(id) for id in ids]),
cols=",".join(['"{}"'.format(col) for col in cols]),
)
我究竟做錯了什么?
uj5u.com熱心網友回復:
這些東西都不應該被“包裝”“在”“雙”“引號”中。也許嘗試這樣的事情:
query = SELECT_QUERY.format(
table='{}'.format(table),
where='{}'.format(where),
ids=",".join(['{}'.format(id) for id in ids]),
cols=",".join(['{}'.format(col) for col in cols]),
)
或者更簡單,呃,TeddyBearSuicide 建議:
query = SELECT_QUERY.format(
table=table,
where=where,
ids=",".join(['{}'.format(id) for id in ids]),
cols=",".join(['{}'.format(col) for col in cols]),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/416748.html
標籤:
