in reply to how to use nested statement handler?

my $pr1 = qq{select customer_name from customer where id = $emp_id } +; my $sth1 = $dbh->prepare($pr1); $sth1->execute(); $cust_id; $sth1->bind_columns( undef, \$cust_id );
I reckon that inspite of the name of the variable it actually contains customer_name which you are comparing with $emp_id which is probably not what you want.

Notes: Use strict and warnings
You most likely could do this with a JOIN. Check the SQL docs.

Update: Also, have a look at Placeholders in the mighty DBI docs.