in reply to SQL error

This:
$stg = $dbh->prepare('SELECT REFERENCE, REQUIREMENTS FROM TestCasesOutput WHERE PassFail = "fail";

has to be
$stg = $dbh->prepare('SELECT REFERENCE, REQUIREMENTS FROM TestCasesOutput WHERE PassFail = "fail"');

It's better to write
my $statement = 'SELECT REFERENCE, REQUIREMENTS FROM TestCasesOutput W +HERE PassFail = "fail"'; my $stg = $dbh->prepare($statement); $stg->execute() or die "An error occured while executing statement: ". +$DBI::errstr;

It is more readable and you will get a more detailed error message...

Replies are listed 'Best First'.
Re^2: SQL error
by Anonymous Monk on Aug 13, 2004 at 13:38 UTC
    #Windows-based Perl/DBI/MS Access example use DBI; #open connection to Access database $dbh = DBI->connect( "dbi:ODBC:driver=Microsoft Access Driver (*.mdb); +dbq=C:TestCasesXP2K.mdb", "", "" ); #prepare and execute SQL statement $stg = $dbh->prepare('SELECT REFERENCE, REQUIREMENT FROM TestCasesOutp +ut WHERE PassFail = "FAIL"'); print "are we getting here"; $stg->execute || die "Could not execute SQL statement ... maybe invalid?"; $sth = $dbh->prepare('SELECT REFERENCE FROM TestCasesOutput'); $sth->execute || die "Could not execute SQL statement ... maybe invalid?"; #output database results $stt = $dbh->prepare('SELECT REQUIREMENT FROM TestCasesOutput'); $stt->execute || die "Could not execute SQL statement ... maybe invalid?"; #output database results while (@row=$stg->fetchrow_array) { @row1=$sth->fetchrow_array; @row2=$stt->fetchrow_array; open(fileOUT, ">>log.txt") or dienice("Can't open log.txt for writ +ing: $!"); flock(fileOUT, 2); seek(fileOUT, 0, 2); print fileOUT "Reference: @row1\n"; print fileOUT "Requirement: @row2\n\n\n\n"; } close(fileOUT);
    Here is the exact code but I am still receiveing the same error.
      Try this instead:
      $stg = $dbh->prepare( q{SELECT REFERENCE, REQUIREMENT FROM TestCasesOutput WHERE PassFail += 'FAIL'} );

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

      The over all goal is to grab certain information out of the database and export to ms word. Right now i am exporting to txt. Do yall know a why to export to MS Word?
        For creating MS Word documents on a Windows machine, look into the Win32::OLE module. There are plenty of code examples, in the documentation (mostly Excel but can easily be converted), on this site (try a Super Search), or via the all knowing google.

        bassplayer

        I bleive that is going to work thank you. But what is the reasoning for putting the q and the brackets.