in reply to Reading from databse and writing to file.

Some of what you're doing makes no sense. You set $ncount to zero, then to a sql statement (and never prepare it, let alone execute it), then you check to see if that statement is greater than '0' (perl has both 'gt' and '>' depending on string or numeric comparison).

Your errcounter and succounter variables are declared at the global level, then you redeclare them in a very limited scope (you need to check out what my really does), and you don't do anything with them in this snippet anyway, so why include in this example?

Instead of asking "Does this work?", it would be better if you actually tried it, see what it does, and then try to fix it. If you are having trouble with any particular part, give some detail about what the problem is with the smallest amount of code possible (and to reduce noise, make up an example with simpler SQL statements, with just a few columns), and we'll still be here :-)

Oh, and welcome to the monestery :-)

  • Comment on Re: Reading from databse and writing to file.

Replies are listed 'Best First'.
Re: Re: Reading from databse and writing to file.
by SQLMan (Novice) on May 15, 2003 at 12:08 UTC
    What I am trying to do with $ncount is reset it to 0 each time in the loop. Then I want to do a query on my database to see if the record is there. The result number should be assigned to the $ncount and if the count is gt 0 then do something else something else.
      What I am trying to do with $ncount is reset it to 0 each time...
      You need to separate your count from your sql statement. And you need to prepare, execute, and fetch from your sql statement (you can do all at once, see the selectrow_array method in the DBI docs).
Re: Re: Reading from databse and writing to file.
by SQLMan (Novice) on May 15, 2003 at 17:58 UTC
    This is the error I get.
    DBD::ODBC::st execute failed: MicrosoftODBC SQL Server DriverCOUNT field incorrect or syntax error (SQL-07001)(DBD: st_execute/SQLExecute err=-1) at Bookkeeping.pl line 51.
    How can I fix it.
      This is the error I get.
      DBD::ODBC::st execute failed: ... How can I fix it.
      You print the sql statement, and see what's wrong with it. If it doesn't work when you cut and paste it into a SQL query window (or whatever query utility you have), then its not going to work in perl. Maybe you need to quote some/all of your arguments, maybe you should use placeholders (see the DBI docs).