我在通过 Python 从 SAP HANA 加载数据时遇到问题。代码在以下情况下工作正常:connection = pyhdb.connect(|||credentials|||)cursor = connection.cursor()cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL')但是当我试图添加像“0COMP_CODE”='B2B'这样的条件时,所以它看起来像这样:Connection = pyhdb.connect(|||credentials|||)cursor = connection.cursor()cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL AND "0COMP_CODE" = 'B2B' ')我越来越SyntaxError: invalid syntax.我做错了什么?
1 回答
青春有我
TA贡献1784条经验 获得超8个赞
尝试转义单引号:
Connection = pyhdb.connect(|||credentials|||)
cursor = connection.cursor()
cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL AND "0COMP_CODE" = \'B2B\' ')
添加回答
举报
0/150
提交
取消