我有一个包含多个表连接的查询,它似乎在MSSQLServer Management Studio上执行没有任何错误,但Pandas返回错误。
"SELECT Ca.LoanAgreementID, Ca.Amount, Ca.TransactionDate, Ca.ContactID, Ca.PaymentType, " \
"Ca.CashLedgerType, Ct.KeyValue_String, Pt.KeyValue_String, Lo.AutoNumber, Lo.IssueDateFROM CashLedger as Ca " \
"LEFT JOIN Enum.CashLedgerTypes as Ct " \
"ON Ca.CashLedgerType = Ct.KeyValue_Int" \
"LEFT JOIN Enum.PaymentTypes as Pt " \
"ON Ca.PaymentType = Pt.KeyValue_Int" \
"LEFT JOIN LoanAgreements as Lo" \
"ON Ca.LoanAgreementID = Lo.LoanAgreementID"
data = pd.read_sql(sql, connection)
错误如下:
pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT Ca.LoanAgreementID, Ca.Amount, Ca.TransactionDate, Ca.ContactID, Ca.PaymentType, Ca.CashLedgerType, Ct.KeyValue_String, Pt.KeyValue_String, Lo.AutoNumber, Lo.IssueDate FROM CashLedger as Ca LEFT JOIN Enum.CashLedgerTypes as Ct ON Ca.CashLedgerType = Ct.KeyValue_IntLEFT JOIN Enum.PaymentTypes as Pt ON Ca.PaymentType = Pt.KeyValue_IntLEFT JOIN LoanAgreements as LoON Ca.LoanAgreementID = Lo.LoanAgreementID': ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Ca'. (102) (SQLExecDirectW)")