Placeholder using DBI

33 views Asked by At

I want to use placeholder for date(3-01-2017) in below query..how to do that ?below is the query i am using in my script using DBI .

$sth = $dbh->prepare("select  CODE_ID,NAME_CODE,SUM(INR_COL + OUT_COL) AS \"TOTAL SUM\"from nwsa where trunc(REPORT_DATE)=to_date('3-01-2017,'dd-mm-yyyy) AND (CODE_ID='A12A' OR CODE_ID='A12B'OR CODE_ID='A12C' OR CODE_ID='A12D' OR CODE_ID='A12E' OR CODE_ID='A12EB' OR CODE_ID='A12F' OR CODE_ID='A12G' OR CODE_ID='A12I' OR CODE_ID='A12O' OR CODE_ID='A12U' ) group by  CODE_ID,NAME_CODE");  # your query here
$sth->execute( );
----this is my complete query ---
SUM(INR_COL + OUT_COL) AS "TOTAL SUM"
FROM nwsa
WHERE trunc(REPORT_DATE) = to_date('3-01-2017','dd-mm-yyyy')
AND (CODE_ID='A12A'
OR CODE_ID   ='A12B'
OR CODE_ID   ='A12C'
OR CODE_ID   ='A12D'
OR CODE_ID   ='A12E'
OR CODE_ID   ='A12EB'
OR CODE_ID   ='A12F'
OR CODE_ID   ='A12G'
OR CODE_ID   ='A12I'
OR CODE_ID   ='A12O'
OR CODE_ID   ='A12U')
GROUP BY CODE_ID,
  NAME_CODE
  ;
1

There are 1 answers

0
Volverine On BEST ANSWER
my $t= '06-01-2017';
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 =$dbh->prepare($sql2);


 $sth->execute($t,'A12A','A12B','A12C','A12D','A12E','A12EB','A12F','A12G','A12I','A12O','A12U');
 $out = DBIx::Dump->new('format' => csv,   # excel or csv
                        'output' => $FILENAME1, # file to save as
                        'sth'    => $sth);
 $out->dump();