douji5397
douji5397
2016-09-15 16:07

我的问题是什么? 将varchar转换为数据类型int时转换失败

I keep getting the error: Conversion failed when converting the varchar value ' BUY0' to data type int, I am unsure what the issue with my code is. the column type for cd_tp_1_item_no is varchar(30)

$customers = array("4470","3650","4322");

foreach($customers as $customer){

$sql = "SELECT DISTINCT cd_tp_1_item_no FROM oeprcfil_sql where cd_tp_1_cust_no = $customer";
$result = odbc_exec($conn,$sql);
$item[] = "";
        while ($row = odbc_fetch_array($result)) {

             $item = $row['cd_tp_1_item_no'];

    }


}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • donglang9880 donglang9880 5年前

    You can use next suggestion to fix your issue:

    $sql = "SELECT DISTINCT cd_tp_1_item_no FROM oeprcfil_sql where cd_tp_1_cust_no = '".(int)$customer."'";
    
    点赞 评论 复制链接分享