T.G. Cornholio has asked for the wisdom of the Perl Monks concerning the following question:
This produces the following output:use DBI; $debug = 1; $| = 1; my $kaiser_file = 'd:\perl\scripts\kevin\excel_data\query.xls'; my $amr_file = 'd:\perl\scripts\kevin\excel_data\data.xls'; $amr_db = DBI->connect("DBI:Excel:file=$amr_file") or die "Cannot connect: " . $DBI::errstr; print "Connected to: $amr_file\n"; foreach $table ($amr_db->tables()) { print "Table: $table "; $sth = $amr_db->prepare("SELECT * from $table LIMIT 2"); $sth->execute(); if ($sth->{NUM_OF_FIELDS} <= 1) { print "has $sth->{NUM_OF_FIELDS} fields. Skipping.\n"; next; } print "has $sth->{NUM_OF_FIELDS} fields. Using this table.\n"; $amr_table = $table; for ($i = 1 ; $i <= $sth->{NUM_OF_FIELDS} ; $i++) { $col_name = $sth->{NAME}->[$i-1]; printf(" Col %2d, Name = \'%s\'\n",$i,$col_name); $amr_col_num{$col_name} = $i; $amr_col_name{$i} = $col_name; } $sth->finish(); } $sql = "SELECT 'Tracking Nbr' FROM $amr_table"; print "$sql\n"; $amr_sth = $amr_db->prepare($sql); $amr_sth->execute(); $row_count = 1; while ($hashref = $amr_sth->fetchrow_hashref()) { print "Row: $row_count\n"; $row_count++; foreach $key (keys (%$hashref)) { print " $key => $$hashref{$key}\n"; } } $sth->finish(); if ($kaiser_db) { print "Disconnecting from kaiser.\n"; $kaiser_db->disconnect(); }
Your guidance is much appreciatedConnected to: d:\perl\scripts\kevin\excel_data\data.xls Table: Kaiser_VRT_Extract_Sac has 23 fields. Using this table. Col 1, Name = 'PupPriority' Col 2, Name = 'PupProblem' Col 3, Name = 'Referral Nbr' Col 4, Name = 'Tracking Nbr' Col 5, Name = 'IncidentNumber' Col 6, Name = 'TCR' Col 7, Name = 'PickupPromised' Col 8, Name = 'DTAlert' Col 9, Name = 'DTEnroute' Col 10, Name = 'DTAtScene' Col 11, Name = 'DTDepartScene' Col 12, Name = 'DTAtDestination' Col 13, Name = 'Cleared' Col 14, Name = 'PupLocName' Col 15, Name = 'PupAddress' Col 16, Name = 'PupZip' Col 17, Name = 'DestLocName' Col 18, Name = 'DestAddress' Col 19, Name = 'PatientName' Col 20, Name = 'CallerType' Col 21, Name = 'CancelReason' Col 22, Name = 'PupRoom' Col 23, Name = 'RunNumber' SELECT 'Tracking Nbr' FROM Kaiser_VRT_Extract_Sac SQL ERROR: Bad table or column name '?0?' has chars not alphanumeric o +r underscore! DBD::Excel::st fetchrow_hashref failed: Attempt to fetch row from a No +n-SELECT statement at test.pl line 35.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI::Excel Help Needed
by JupiterCrash (Monk) on Nov 24, 2002 at 21:35 UTC | |
by T.G. Cornholio (Scribe) on Nov 26, 2002 at 03:18 UTC |