The Select works fine in Sybase but in the code below it gives me errors. When I striped out the Case When from the select statement it worked fine. Does anyone know how to write it with the case when. Thanks
use strict; use warnings; use DBI; #use Win32::ODBC; use DBD::ODBC; # Global Variables my @statement; # Array of sql statements that will be used for Sql my @data; # Array of table rows read from Sybase my @message; # Array of error messages used for debugging Sql # SQL Connection my $dbh = DBI->connect( "dbi:ODBC:RETDEV_SQL", "User", "Pass", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: ";#. $DBI::errstr . "\n"; # Sybase Connection my $dbh2 = DBI->connect( "dbi:ODBC:BPSA", "User", "Pass", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: ";#. $DBI::errstr . "\n"; #Create the sql statement for Sybase and execute it $sth = $dbh2->prepare("SELECT (dbo.tacat_trnfr.branch_cd + dbo.tacat_t +rnfr.acct_cd) As AccountNo,case when (dbo.tacat_trnfr.dlvr_nbr= '0044 +') then 'RCV_NBR' when (dbo.tacat_trnfr.rcv_nbr = '0044')then 'DLVR _ +NBR' end As ContraFirmNo, case when (dbo.tacat_trnfr.trnfr_type_cd = 'FUL' or dbo.tacat_trnfr. +trnfr_type_cd = 'PTD')then 'ACT' when (dbo.tacat_trnfr.trnfr_type_cd += ' PTR') then 'PCT' end as TransferType, case when (dbo.tacat_trnfr.dlvr_nbr= '0044') then 'DLR' when (dbo.taca +t_trnfr.rcv_nbr = '0044')then 'TRI'end As TransferFlag, case when (dbo.tacat_trnfr.stts_cd = '140') then 'S' when (dbo.tacat_t +rnfr.stts_cd = '300'or dbo.tacat_trnfr.stts_cd = '310') then 'C' when + (dbo.tacat_trnfr.stts_cd = '400' or dbo.tacat_trnfr.stts_cd = '500' +or dbo.tacat_trnfr.stts_cd = '600') then 'H'end as RejectType, dbo.tacat_trnfr.cmnt_txt as Comment FROM dbo.tacat_trnfr WHERE dbo.tacat_trnfr.stts_cd in ('140','300','310','400','500','600') +"); $sth->execute; my $insh=$dbh->prepare("INSERT INTO TestClearTransferData(AccountNo,Co +ntraFirmNo,TransferType,RejectType,Comment) VALUES ( ?,?,?,?,?)"); eval { while((@data) = $sth->fetchrow_array) { $insh->execute(@data); } }; if($@) { print STDERR "The insert died: $@"; } #Close the sql DB Connection $dbh->disconnect; #Close the Sybase DB connection $sth->finish; $dbh2->disconnect;

In reply to Problem with case in select statement by SamueD2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.