Below is part of my code. What I am trying to do is select from a database and assign to
one of the fields the DATE, Field1, and Line number. I am increasing the line
number inn the while loop but I am preparing the select outside the loop so my
results are Date, Field1 and 0 for line number. How can I have the select pick up the
incremented line number or is there a better way to do it.

# #Create the sql statement for Sybase and execute it my $sth = $dbh2->prepare("SELECT (dbo.tbookkeeping_trans.branch_cd + d +bo.tbookkeeping_trans.account_cd)As AccountNo, 'TRI'as TransferFlag,'NCT' as TransferType, 'C' as RejectType, dbo.tbo +okkeeping_trans.security_adp_nbr as pNumber, dbo.tbookkeeping_trans.share_trans_qty as Shares,dbo.tbookkeeping_tra +ns.processing_dt, (dbo.tbookkeeping_trans.branch_cd + dbo.tbookkeeping_trans.account_cd ++'".$datestamp."'+'".$lineno."')As KeyId FROM dbo.tbookkeeping_trans + WHERE (dbo.tbookkeeping_trans.client_nbr='0030' AND dbo.tbookkeeping_t +rans.entry_cd IN ('JNL', 'JRL', 'REC') AND dbo.tbookkeeping_trans.branch_cd >'248') ORDER BY 1"); $sth->execute; my $insh=$dbh->prepare("INSERT INTO ClearTransferData(AccountNo, Trans +ferFlag, TransferType, RejectType, AdpNumber, Shares, ProcessingDate, +KeyId) VALUES ( ?, ?, ?, ?, ?, ?, ? ,?)"); eval { while((@data) = $sth->fetchrow_array) { $lineno++; my $keyId = ("$data[0]".$lineno.$datestamp); print "$keyId\n"; my $sql=("Select Count(*) From ClearTransferData Where AccountNo = +'$data[0]' and TransferFlag = '$data[1]' and TransferType = '$data[2 +]' and RejectType = '$data[3]' and AdpNumber = '$data[4]' and Shares += '$data[5]' and ProcessingDate = '$data[6]' "); my ($ncount) = $dbh->selectrow_array($sql); print "$ncount\n"; if ($ncount > 0) { $errcounter++; print OUTFILE "@data\n"; } else { $insh->execute(@data); $succounter++; } } };

update (broquaint): added <code> tags


In reply to Counter and select statement by SQLMan

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.