I am getting an error when I try to bind parameters to a sql statement that includes a UNION statement. Here is my code:
$sql="SELECT DISTINCT cp.model_code, p.product_code, cp.model_desc, cp.eur_na, '2005' calendar_year, cp.volume, cp.vehicle_pgm_center, cp.valid, TO_CHAR(cp.record_cd,'DD-MON-YYYY') record_cd, cp.veh_type,cp.family_unit,cp.family_name, p.product_desc, p.product_group, p.product_family, NVL(cp.vehicle_mix,0) vehicle_mix, VolumesMixes.getProduct(p.product_code) product_type, VolumesMixes.ptoRecord(cp.model_code, cp.calendar_year) ptoRecord, cp.product_code product_code1, 'a' sortOrder
FROM calendar_product cp, product p
WHERE cp.calendar_year = ?
AND cp.eur_na = ?
AND cp.model_code = ?
AND p.product_code = cp.product_code
UNION SELECT cp.model_code, '' product_code, cp.model_desc, cp.eur_na, '2005' calendar_year, volumesMixes.getVolume('TVU8', '2005') volume, '' vehicle_pgm_center, 'N' valid, '' record_cd, cp.veh_type, cp.family_unit, cp.family_name, '' product_desc, '' product_group, '' product_family, 0 vehicle_mix, VolumesMixes.getProduct(cp.product_code) product_type, VolumesMixes.ptoRecord(cp.model_code, cp.calendar_year) ptoRecord, '' product_code1, 'x' sortOrder
FROM calendar_product cp, model m
WHERE cp.model_code = m.model_code
AND cp.calendar_year(+) = ?
AND cp.eur_na = ?
AND cp.model_code = ?
AND cp.product_code = 'VEHL'
ORDER BY 20,2 DESC";
$sth = $dbh->prepare($sql);
$sth->bind_param(1,$calYear);
$sth->bind_param(2,$region);
$sth->bind_param(3,$modelCode);
$sth->execute || &dberror($selectVehicleSql);
If I remove all sql below the UNION statement, it works. I include the Union and the rest of the SQL statement, it bombs.
Any suggestions?
$sql="SELECT DISTINCT cp.model_code, p.product_code, cp.model_desc, cp.eur_na, '2005' calendar_year, cp.volume, cp.vehicle_pgm_center, cp.valid, TO_CHAR(cp.record_cd,'DD-MON-YYYY') record_cd, cp.veh_type,cp.family_unit,cp.family_name, p.product_desc, p.product_group, p.product_family, NVL(cp.vehicle_mix,0) vehicle_mix, VolumesMixes.getProduct(p.product_code) product_type, VolumesMixes.ptoRecord(cp.model_code, cp.calendar_year) ptoRecord, cp.product_code product_code1, 'a' sortOrder
FROM calendar_product cp, product p
WHERE cp.calendar_year = ?
AND cp.eur_na = ?
AND cp.model_code = ?
AND p.product_code = cp.product_code
UNION SELECT cp.model_code, '' product_code, cp.model_desc, cp.eur_na, '2005' calendar_year, volumesMixes.getVolume('TVU8', '2005') volume, '' vehicle_pgm_center, 'N' valid, '' record_cd, cp.veh_type, cp.family_unit, cp.family_name, '' product_desc, '' product_group, '' product_family, 0 vehicle_mix, VolumesMixes.getProduct(cp.product_code) product_type, VolumesMixes.ptoRecord(cp.model_code, cp.calendar_year) ptoRecord, '' product_code1, 'x' sortOrder
FROM calendar_product cp, model m
WHERE cp.model_code = m.model_code
AND cp.calendar_year(+) = ?
AND cp.eur_na = ?
AND cp.model_code = ?
AND cp.product_code = 'VEHL'
ORDER BY 20,2 DESC";
$sth = $dbh->prepare($sql);
$sth->bind_param(1,$calYear);
$sth->bind_param(2,$region);
$sth->bind_param(3,$modelCode);
$sth->execute || &dberror($selectVehicleSql);
If I remove all sql below the UNION statement, it works. I include the Union and the rest of the SQL statement, it bombs.
Any suggestions?