CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Printing SQL result using While loop


New User

Aug 23, 2012, 10:22 AM

Post #1 of 3 (823 views)
Printing SQL result using While loop Can't Post


I'm trying to write a simple script that prints out (and eventually emails) a list of data from a SQL Query.

When I don't put the data in the While loop, my script successfully print out the first data from the Query result. However trying with a WHILE loop, it seems to be in infinite loop.. I know I'm missing a basic here.

Thanks for your help.

#declaring my database connection
my $ABConn = Win32::OLE->new('ADODB.Connection');
$conn_str = "Provider=sqloledb;Data Source=TestServer;"
$conn_str .= "Database=TestDatabase;Trusted_Connection=yes";
CheckErrors($ABConn, $conn_str);
$SBEConn->{CommandTimeout} = 900;


sub CheckMissingCode
my $sql =<<"EOQ";
SELECT m.merchant_id, m.merchant_name
FROM Merchant m
WHERE code = ''

my $Rec1 = $ABConn->Execute($sql);
CheckErrors($ABConn, $sql);

if (!$Rec1->EOF)
print STDOUT "\tMissing Merchant Codes:\n";
while (!$Rec1->BOF && !$Rec1->EOF)
$prop = $Rec1->Fields("merchant_name")->Value;
$MID = $Rec1->Fields("merchant_id")->Value;
print STDOUT "* $prop \t $MID";

Veteran / Moderator

Aug 23, 2012, 10:34 AM

Post #2 of 3 (820 views)
Re: [kuroneko1313] Printing SQL result using While loop [In reply to] Can't Post

I do not know the syntax of the module you are using, but I have the impression that the while loop keeps looping on the first line of the SQL output, since you have nothing in this loop which tells the while loop to go to the next record.

What does the $Rec1 look like? Is it a multi-line string?

New User

Aug 23, 2012, 11:07 AM

Post #3 of 3 (819 views)
Re: [Laurent_R] Printing SQL result using While loop [In reply to] Can't Post

Solved it.. just figured out I need to put below in order to move forward the WHILE loop.



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives