具有多个条件的where子句使用和运算符

时间:2017-01-21 12:47:51

标签: sql

下面的代码是错误的:

  

“发生了'System.InvalidCastException'类型的未处理异常   在Microsoft.VisualBasic.dll

中      

附加信息:从字符串“SELECT Items.itm_gsm”转换,   Items.itm_“键入'Long'无效。”

sql_lotitems3 = "SELECT Items.itm_gsm, Items.itm_size, LotItems.lot_itm_qty
    FROM (Items
    INNER JOIN LotItems ON LotItems.itm_code = Items.itm_code)
    INNER JOIN LotMaster ON LotMaster.lot_code = LotItems.lot_code
    WHERE LotMaster.po_number =" & ponum And "LotMaster.lot_number=" & lotnum

当我只使用WHERE子句(ponum或lotnum)中的一个条件而没有当然的操作符时,它工作正常...

1 个答案:

答案 0 :(得分:0)

使用“And之后

尝试在SQL语句中包含ponum
sql_lotitems3 = "SELECT Items.itm_gsm, Items.itm_size, LotItems.lot_itm_qty
    FROM (Items
    INNER JOIN LotItems ON LotItems.itm_code = Items.itm_code)
    INNER JOIN LotMaster ON LotMaster.lot_code = LotItems.lot_code
    WHERE LotMaster.po_number =" & ponum & " And LotMaster.lot_number=" & lotnum