Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl DBI - Bind Parameters Problem

Status
Not open for further replies.

mh53jfe

Technical User
Nov 20, 2000
9
US
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?
 
I am just taking a guess here..
but shouldnt you be including three more bind parameters
for the three "?" in the union statement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top