my $query_records2 = $conn->prepare($mainquery) or die("Error on preparing the sql statement2 \n"); $query_records2->execute() or die("Error on getting the data from QUERYDETAIL \n");