
kuroneko1313
New User
Aug 23, 2012, 10:22 AM
Post #1 of 3
(497 views)
|
|
Printing SQL result using While loop
|
Can't Post
|
|
Hi, 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"; $SBEConn->Open($conn_str); CheckErrors($ABConn, $conn_str); $SBEConn->{CommandTimeout} = 900; CheckMissingCode(); sub CheckMissingCode { my $sql =<<"EOQ"; SELECT m.merchant_id, m.merchant_name FROM Merchant m WHERE code = '' EOQ 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"; } } }
|