#!/cluster/uapp/perl/bin/perl -w use KAP ## A internally developed module with custom code to access the Database. use strict; use DBAccess; use DBD::CSV; my $db_lv_conn_file = "MSLV.eq_script_user"; my $read_dbi = undef; # Run stored proc my $sp = "lv..check_tax_lot"; ##This is the Stored Procedure that gives me back 7 Resultsets ### $read_dbi = KAP::opendbi($_db_lv_conn_file) || handle_error_and_exit ("Failed to get a connection to MSLV db server"); my $read_sth = $_read_dbi->prepare($sp); if($DBI::err) { handle_error_and_exit("**ERROR preparing $sp: " . $DBI::errstr); } KAP::write_log("Prepare done, executing $sp"); $read_sth->execute(); if($DBI::err) { handle_error_and_exit( "**ERROR executing $sp: " . $DBI::errstr); } KAP::write_log("Execute of $sp done"); my $datafile = "output.csv"; my $numrecords = 0; my @data = undef; # Loop through the data and write to file ##This is where I start to write into the .csv file## ##But it only writes the one resultset and discards the rest 6.## my $header_rec = join(",", @{$read_sth->{NAME}}); print $datafile $header_rec . "\n"; while (@data = $read_sth->fetchrow_array) { @data = EQ_Misc::arr_replace_undef("", @data); my $csv_record = join(",", @data); open (FH, ">>$datafile") or die "$!"; print FH "@data $csv_record .\n";; close $datafile; }