Volverine
Volverine

Reputation: 75

prepare command not working with DBI

I am trying to do this but it is not working

 my $sql2 = "SELECT CODE_ID,NAME_CODE,SUM(INR_COL + OUT_COL) AS \"TOTAL SUM\" FROM nwsa WHERE trunc(REPORT_DATE) = to_date('?','dd-mm-yyyy')AND CODE_ID IN (?,?,?,?,?,?,?,?,?,?,?)GROUP BY CODE_ID,NAME_CODE"; 
     $sth ->prepare($sql2);
     my $t= "06-01-2017";

     $sth->execute($t,'A12A','A12B','A12C','A12D','A12E','A12EB','A12F','A12G','A12I','A12O','A12U');

Upvotes: 0

Views: 135

Answers (1)

Dr.Avalanche
Dr.Avalanche

Reputation: 2006

You have:

$sth ->prepare($sql2);

you need:

my $sth = $dbh->prepare($sql2);

https://metacpan.org/pod/DBI#prepare

Also consider the prepare_cached method, depending on what you are actually doing:

https://metacpan.org/pod/DBI#prepare_cached

Upvotes: 5

Related Questions