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

Hello Monks, I'm seeking your wisdom. I'm not familiar with DBI but I have a task that I need to accomplish. I'm trying to connect to a database and query a table. Then the output put it into a file with a comma delimiter. I'm passing a variable to the subroutine but it looks like is not querying anything. the code runs without any errors or warnings but It doesn't create an output. Could you take a look at the code and let me know what do I'm doing wrong to modify it and make it work. I will appreciate any suggestions. Thanks in advance. Here is the code:
#! perl -w use strict; use Win32::ODBC; my $dir = 'K:\\reports'; my $count = 0; opendir DH, $dir or die "Cannot open $dir: $!"; while (my $file = readdir DH) { next unless $file =~ /\.pdf$/; my $newfile = substr($file,2,6); process_records($newfile); } closedir DH; sub process_records { my ($newfile) = @_; my $dbname = 'dbname'; my $username = 'account'; my $password = 'password'; my ($db); if (!ref($db = new Win32::ODBC("DSN=$dbname;UID=$username;PWD=$passwo +rd"))) { my ($ErrNum, $ErrText, $ErrConn) = Win32::ODBC::Error(); #...IT FAILED - DO SOMETHING... } my $sql = "SELECT field1#,field2#,field3#,field4#,field5#,field6,lastn +ame,firstname FROM dbo.table WHERE field2# = $newfile"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:\\Directory\\%04d%02d%02d.txt",$yr+1900,$mo+ +1,$dy ); open OUT,">$outfile" or die "Couldn't open $outfile, $!"; print OUT "$sql\n"; if($db->Sql($sql)){ #...FAILED... my ($ErrNum, $ErrText, $ErrConn) = $db->Error(); } while($db->FetchRow()){ my %data = $db->DataHash(); #...Processing Data... } $db->Close(); }