如何避免SQL DB2问题?

gcuhipw9  于 2023-02-08  发布在  DB2
关注(0)|答案(1)|浏览(206)

当我手动运行此查询时,它可以正确执行,没有任何问题,我可以获得商店编号和项目编号,但当我在框架中使用它并将场景步骤连接到Db2时,它给我一个错误。
cursor.execute("select * from qs36f.DSTHSTP join qs36f.calendar on date_ccyymmd = dhindt where date_iso between(current date - 10 day) and current date and DHCUS# in (" + open_stores + ") and dhqtss>=1 and DHCLSS = " + class_nbr + " and dhsbcl = " + sub_class_nbr + " and ((dhqtss*dhrt5s)*DHPACK) <" + end_range + "")
我不知道这里有什么问题。这是错误:::

cursor.execute("select * from qs36f.DSTHSTP join qs36f.calendar on date_ccyymmd = dhindt where date_iso between(current date - 10 day) and current date and DHCUS# in (" + open_stores + ") and dhqtss>=1 and DHCLSS = " + class_nbr + " and dhsbcl = " + sub_class_nbr + " and ((dhqtss*dhrt5s)*DHPACK) <" + end_range + "")
pyodbc.ProgrammingError: ('42000', '[42000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 - Token , was not valid. Valid tokens: FOR USE SKIP WAIT WITH FETCH LIMIT ORDER UNION EXCEPT OFFSET. (-104) (SQLExecDirectW)')

我的期望是我必须从数据库中检索存储编号和项目编号。

mkh04yzy

mkh04yzy1#

看起来您遇到了语法错误。因此您的语句是:

select * 
from qs36f.DSTHSTP 
join qs36f.calendar 
    on date_ccyymmd = dhindt 
where date_iso between (current date - 10 day) and current date 
    and DHCUS# in (" + open_stores + ") 
    and dhqtss>=1 
    and DHCLSS = " + class_nbr + "
    and dhsbcl = " + sub_class_nbr + " 
    and ((dhqtss*dhrt5s)*DHPACK) <" + end_range + "

可能是您没有正确构建它,在这种情况下,请尝试从WHERE子句中删除一行,然后执行查询以找到不正确的行。

相关问题