ประมาณนี้ไหมครับที่ต้องการ
Value := GetSQLStringData('select count(distinct v.hn) from vn_stat v '+
' left outer join depression_screen d on d.vn = v.vn '+
' where v.vstdate between "'+ds1+'" and "'+ds2+'" and d.vn = v.vn and v.sex ="1"'+
' and (d.depression_score >= "19") and v.hn not in '+
' (select distinct(hn) from vn_stat where vstdate between "2012-10-1" and "2013-09-30" )');