Writing sql results to file using ksh -nevermind

I'm having problems with writing my sql results to a file:

sqlplus -S username/password@DB <<!!

set echo off
set verify off
set showmode off
set feedback off 
set timing off
set linesize 250 
set wrap off
set pagesize 0
set newpage none
set tab off
set trimspool on
set colsep ','

spool $TVXTEMP
select acct_id, customer_name, amount, date, phone_num
from table;
spool off

function createfile {
rm -f $1
awk -v typ="$3" -v prdt=$(date '+%m/%d/%Y') -v fout=$1 \
   'BEGIN {FS=",";c=1; 
           fmt="%-10s %-30s %-10s %-10s %-10s\n";
           printf "acct_id,customer_name,amt,date,phone_num,call_loc\n" > fout;
   /^'$3'/ {printf "%s,%s,%s,%s,%s,%d\n",$1,$2,$3,$4,$5,c > fout;
           if (c<=6) c+=1; else c=1;
           printf fmt,$1,$2,$3,$4,$5 > fout}' $TVXTEMP
}

file1=file1.txt

createfile $file1 

The file just prints the first 2 columns - acct_id, customer_name. I think the results are not written to $TVXTEMP correctly, and I don't know how to fix it..

---------- Post updated at 01:55 AM ---------- Previous update was at 01:48 AM ----------

Nevermind, I figured it out already. :smiley:

Consider letting us know how you solved it next time, please.