ciamack has asked for the wisdom of the Perl Monks concerning the following question:

I use Win32::OLE "ADODB.Connection" and so far it has been easy to fetch data stored fields or cells in a MS
Access DB.

Here is a sample of code I use:

$RS = $Conn->Execute("SELECT Orders.OrderID FROM Orders");
while ( !$RS->EOF ) {
  $orderid = $RS->Fields('OrderID')->value;
$RS->MoveNext;
}

I need to count number of rows containig particular data like 0 or 1. There is a simple SQL statment for this:

SELECT COUNT(*) FROM Orders WHERE Orders.Sent=0;

But I dont't know how to fetch the result from this SQL statment.
Any suggestions and help is greatly appreciated.
Thanks
  • Comment on How do I fetch result from SELECT COUNT(*) FROM ....

Replies are listed 'Best First'.
Re: How do I fetch result from SELECT COUNT(*) FROM ....
by talwyn (Monk) on Jun 30, 2002 at 12:46 UTC
    I don't use that particular module but here's my 2 cents worth. --Talwyn
    Try SELECT COUNT(*) AS Order.count FROM Orders WHERE Orders.Sent=0; and access it through the field alias
    $count = $RS->Fields('count')->value;
      Thanks, It worked fine with a small adjustion:
      SELECT COUNT(*) AS expr1 FROM Ordes WHERE Orders.Sent=0;
      $count = $RS->Fields('expr1')->value;

      expr1 can be anything but Orders.count or count because Orders table doesn't have a 'count' column
      and word 'count' is reserved in SQL language.