Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^8: SQL query using elements from array

by AllPaoTeam (Acolyte)
on Oct 13, 2014 at 17:35 UTC ( [id://1103650]=note: print w/replies, xml ) Need Help??


in reply to Re^7: SQL query using elements from array
in thread SQL query using elements from array

Can you write me an example, I am not sure how to do that. Thanks again for taking the time to help me. -Pao
  • Comment on Re^8: SQL query using elements from array

Replies are listed 'Best First'.
Re^9: SQL query using elements from array
by mje (Curate) on Oct 14, 2014 at 08:03 UTC

    Try this, untested:

    use Data::Dumper; my $sth = $dbh->prepare($sql2); $dbh->{RaiseError} = 1; foreach my $i (0 .. @date1 - 1) { eval { $sth->execute($date1[$i], $date2[$i]); my @row; while (@row = $sth->fetchrow_array) { # retrieve one row at +a time print join(", ", @row), "\n"; } }; if ($@) { print "$@\n"; print Dumper($sth->{ParamValues}); } }
      Yea I ran this but got the error:
      Use of uninitialized value in subroutine entry at c:/Perl64/lib/DBD/OD +BC.pm line 166.

        I can only guess you have an old version of DBD::ODBC - what version have you got? This self contained example works for me:

        use strict; use warnings; use DBI; use Data::Dumper; my $h = DBI->connect("dbi:ODBC:xxx","xxx","xxx", {RaiseError => 1, Pri +ntError => 0}); eval { $h->do(q/drop table mje/); }; $h->do(q/create table mje (a int)/); $h->do(q/insert into mje values(1)/); my $s = $h->prepare(q/select * from mje where a = ?/); eval { $s->execute('fred'); }; if ($@) { print "$@"; print Dumper($s->{ParamValues}); } # outputs # DBD::ODBC::st execute failed: [unixODBC][Easysoft][SQL Server Driver + #11.0][SQL Server]Invalid character value for cast specification (SQ +L-22018) #at paramvalues.pl line 17. #$VAR1 = { # '1' => 'fred' # };
Re^9: SQL query using elements from array
by poj (Abbot) on Oct 13, 2014 at 18:03 UTC
    Try running this script
    #!perl use strict; use DBI; my $dbh = dbh(); my $sql ="select * from information_schema.columns where table_name = ?"; my @tables = ('TopsData.dbo.AUDT_AuditChrt','TopsData.dbo.AUDT_AuditMe +dication'); for my $table (@tables){ my $ar = $dbh->selectall_arrayref($sql,undef,$table); for (@$ar){ print join ":",@$_,"\n"; } } # connect sub dbh { my $dsn = "dbi:ODBC:DSN=TEST-DB1"; my $dbh = DBI->connect($dsn, 'SA', 'pass', {RaiseError => 1, PrintError => 1}) or die (Error connecting " $DBI::errstr"); }
    poj
      Odd, it ran successfully but did not print anything, would you have an idea why?
        Try using just the table name in the select
        my @tables = ('AUDT_AuditChrt','AUDT_AuditMedication');
        poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103650]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-23 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found