#!perl use warnings; use strict; use DBI; my @col = qw(RECORD SUBSCRIPT ID_SUBSTN CO_SUBSTN AREA_SUBSTN ID_DEVTYP ID_DEVICE NAME_DEVICE AREA_DEVICE ID_MEAS ID_POINT SITE_POINT AREA_POINT); my $cols = join ",",@col; # Create connection string to database point.csv my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_ext => ".csv/r", f_encoding => "utf-8", }); my $sth = $dbh->prepare ("SELECT $cols FROM point WHERE ID_DEVTYP LIKE 'INTELI%' AND ID_POINT LIKE 'AUTO%'"); $sth->execute; # Create AFS CSV with Columns open DAT_OUTPUT,'>','AFS.csv' or die "Could not open AFS.csv : $!"; print DAT_OUTPUT $cols."\n"; # Cycle through SQL results on ROW basis and print to AFS CSV file while (my @row = $sth->fetchrow_array) { print DAT_OUTPUT (join ",",@row)."\n"; } # Close file close DAT_OUTPUT;