unload to "/tmp/sql2.unl" DELIMITER "|" select wbdconf.recordno, wbdconf.distid, wbdconf.distiddesc, wbdconf.lastdist, wbdconf.lastdistdate, wbdconf.altemail, wbdconf.altemailyn, wbdconf.wbd_method, wbdconf.wbd_type, tPerson.emailaddress, wbdconf.passwd, wbdconf.sdate, wbdconf.edate, wbdlist.grid, tPerson.emailaddress from wbdconf, wbdlist, tPerson where wbdconf.distid = wbdlist.distid and wbdconf.userid = "email" and (tPerson.emailaddress is not null and tPerson.emailaddress != " ") and wbdconf.recordno = tPerson.PersonID and wbdconf.sdate <= "31/03/2012" and (wbdconf.edate IS NULL or (wbdconf.edate IS NOT NULL and wbdconf.edate > "31/03/2012") ) order by 1, 2