查询未正确过滤数据

时间:2016-01-21 05:19:59

标签: oracle

我对gridview进行了过滤,该过滤基于project_iddatevehicle_no

但我的查询未正确过滤。

问题是: -

  1. 如果我过滤今天的日期并检查,则记录不会显示和数据,这是完全正确的。

  2. 但如果过滤exact dateproject_idvehicle_no,则应显示一条记录。但它仍然没有显示任何记录。

  3. 以下是我对过滤的查询。

    strquerry = "SELECT DISTINCT sv.mkey, vehicle_no, TO_CHAR (date_in, 'dd/MM/yyyy') || ' & ' || time_in vehicleindate_time, TO_CHAR (date_out, 'dd/MM/yyyy') || ' & ' " +
                 "|| time_out vehicleoutdate_time, gate_no_in || ' & ' || gate_no_out ingate_outgateno, gd.good_type goods_type, net_weight netweight, TO_CHAR (challan_date, 'dd/MM/yyyy') " +
                 "|| ' & ' || challan_no challandate_no,remark_in remarkin, NULL receipt_no, date_in FROM xxcus.xxgid_supinv sv, xxcus.xx_supinv_goodtype gd, " +
                 "xxcus.xxacl_xxgid_user_mst ms WHERE (gd.good_type_code(+) = sv.good_type) AND " +
                 "( sv.project_id = '" + cmbProjectName.SelectedValue + "' AND TO_CHAR (date_in, 'dd/MM/yyyy') = '" + txtExpCal.Value + "' OR vehicle_no = '" + ddlVehicleno.SelectedValue + "' ) ORDER BY date_in DESC, vehicle_no";
    

    更新

    调试后的真实查询

    SELECT DISTINCT sv.mkey, vehicle_no,
                   TO_CHAR (date_in, 'dd/MM/yyyy')
                || ' & '
                || time_in vehicleindate_time,
                   TO_CHAR (date_out, 'dd/MM/yyyy')
                || ' & '
                || time_out vehicleoutdate_time,
                gate_no_in || ' & ' || gate_no_out ingate_outgateno,
                gd.good_type goods_type, net_weight netweight,
                   TO_CHAR (challan_date, 'dd/MM/yyyy')
                || ' & '
                || challan_no challandate_no,
                remark_in remarkin, NULL receipt_no, date_in
           FROM xxcus.xxgid_supinv sv,
                xxcus.xx_supinv_goodtype gd,
                xxcus.xxacl_xxgid_user_mst ms
          WHERE (gd.good_type_code(+) = sv.good_type)
            AND (       sv.project_id = '1368'
                    AND TO_CHAR (date_in, 'dd/MM/yyyy') = '19-09-2015'
                 OR vehicle_no = '29'
                )
       ORDER BY date_in DESC, vehicle_no
    

1 个答案:

答案 0 :(得分:1)

问题是TO_CHAR (date_in, 'dd/MM/yyyy') = '19-09-2015'

您使用/分隔符转换日期,但参数中的日期具有-分隔符。

将其更改为TO_CHAR (date_in, 'dd-MM-yyyy')