Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Counter and select statement

by pfaut (Priest)
on May 20, 2003 at 14:12 UTC ( #259455=note: print w/replies, xml ) Need Help??


in reply to Counter and select statement

You interpolated $lineno into your SQL statement outside the loop. The value it held at the time was embedded into the SQL statement and was used for all rows returned.

You could easily create the field where you are using $lineno with perl instead of having the database return it. The data coming from the database is already present in the list of fields - you are just appending $datestamp and $lineno to this. It doesn't make sense to give data to the database just to have the database return it.

Some other notes...

You can use placeholders on select statements as well as on inserts. Why do you use it for one and not the other? Placeholders are a much cleaner way to plug data into your SQL than string interpolation.

Some of the fields in your first select were literals which you just took and plugged into another SQL statement. You could have just coded the SQL statements with those constants.

my $sth = $dbh2->prepare(<<SQL); SELECT branch_cd + account_cd As AccountNo, security_adp_nbr as pNumber, share_trans_qty as Shares, processing_dt FROM dbo.tbookkeeping_trans WHERE client_nbr='0030' AND entry_cd IN ('JNL', 'JRL', 'REC') AND branch_cd >'248' ORDER BY 1 SQL $sth->execute; my $cnth=$dbh->prepare(<<SQL); Select Count(*) From ClearTransferData Where AccountNo = ? and TransferFlag = 'TRI' and TransferType = 'NCT' and RejectType = 'C' and AdpNumber = ? and Shares = ? and ProcessingDate = ? SQL my $insh=$dbh->prepare(<<SQL); INSERT INTO ClearTransferData(AccountNo, TransferFlag, TransferType, RejectType, AdpNumber, Shares, ProcessingDate,KeyId) VALUES ( ?, 'TRI', 'NCT', 'C', ?, ?, ? ,?) SQL eval { while((@data) = $sth->fetchrow_array) { $lineno++; my $keyId = ("$data[0]".$lineno.$datestamp); print "$keyId\n"; $cnth->execute(@data); my ($ncount) = $cnth->fetchrow_array($sql); my $KeyID = $data[0] . $datestamp . $lineno; print "$ncount\n"; if ($ncount > 0) { $errcounter++; print OUTFILE "@data\n"; } else { $insh->execute(@data,$KeyID); $succounter++; } } };
90% of every Perl application is already written.
dragonchild

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://259455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-02-27 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?