in reply to Undefined value from DBI

No problem at all for DBI. I ran your SQL without problem in the postgres dialect:

#!/bin/env perl use strict; use warnings; use Data::Dumper; use DBI; # table my_table; # first | middle | last # -------+--------+------ # joe | john | sean # joe | john | sean # joe | john | sean # pet | joe | sean # pet | zoe | joe # ken | zoe | joe # (6 rows) # (picking up dsn from environment:) my $dbh = DBI->connect or die "oops - no db connection\n"; $dbh->{RaiseError} = 1; my $sql = " with data_count as ( select sum(case when FIRST = 'joe' then 1 else 0 end) as a_count , sum(case when MIDDLE = 'joe' then 1 else 0 end) as b_count , sum(case when LAST = 'joe' then 1 else 0 end) as c_count from my_table where FIRST like 'joe%' or MIDDLE like 'joe%' or LAST like 'joe%' ) select 'Search by: ' || 'joe' union all select 'Found ' || cast(a_count as integer) || ' ' || 'joe' +|| ' for First' from data_count union all select 'Found ' || cast(b_count as integer) || ' ' || 'joe' +|| ' for Middle' from data_count union all select 'Found ' || cast(c_count as integer) || ' ' || 'joe' +|| ' for Last' from data_count " ; # ?column? # ------------------------ # Search by: joe # Found 3 joe for First # Found 1 joe for Middle # Found 2 joe for Last # (4 rows) my $sth = $dbh->prepare($sql); $sth->execute() or die "SQL Error: $DBI::errstr\n"; my $data = $sth->fetchall_arrayref({}); warn Dumper $data;

which results in the expected output (proving that neither DBI nor the general SQL is at fault):

$VAR1 = [ { '?column?' => 'Search by: joe' }, { '?column?' => 'Found 3 joe for First' }, { '?column?' => 'Found 1 joe for Middle' }, { '?column?' => 'Found 2 joe for Last' } ];

(A further variant with placeholders also gave no problem (in postgres). )

What database are you using? What is the error you get? Is there anything in the database logfile?