uncle0 发表于 2020-4-18 17:42:03

关于SQL查询的问题

import pymssql
PL ='ooA5'
Stock = '1,2,3,4'
conn = pymssql.connect(server='AA', user='sa', password='FF', database='CC',
                               charset='utf8')
sql = "select a.productID,fullName,b.storageName," \
      "convert(int,isnull(d.orderAmount,0)) as orderAmount," \
      "convert(int,isnull(d.roadamount,0)) as roadamount," \
      "convert(int,isnull(d.amount,0)) as amount," \
      "convert(int,isnull(d.money,0)) as money " \
      "from EIM_BSS_Basic_Products a cross join " \
      "EIM_BSS_Basic_Storage b join " \
      "EIM_BSS_Stat_ProductStorage c on a.productID=c.productID Left join " \
      "EIM_BSS_Stat_ProductSubStorage d on a.productID=d.productID and b.storageID=d.storageID Left join " \
      "EIM_BSS_Basic_ProductCategories e on a.productCategoryID=e.productCategoryID Left join " \
      "EIM_BSS_Basic_ProductCategories f on left(a.productCategoryID,4)=f.productCategoryID " \
      "where left(a.productCategoryID,4) = %s and b.storageid in (%s)" \
      "order by fullName ,left(a.productCategoryID,4),a.productCategoryID,a.productid,b.storageID"
cursor0 = conn.cursor()# 创建游标0
cursor0.execute(sql,(PL,Stock))# 执行sql
sqlData = cursor0.fetchall()
cursor0.close()
conn.close()
print(sqlData)

谁能帮忙解释下为什么一直错吗?放入一个参数就可以,2个就不行了。

wp231957 发表于 2020-4-18 17:52:11

这款sql没用过,建议你先在数据库环境里通过
或者navicat里也能测试
页: [1]
查看完整版本: 关于SQL查询的问题