Date invoiceDate=rsOldTrans.getDate(3);
int periodId=0;
rsPeriods.beforeFirst();
//find the appropriate period if it exists.
while (rsPeriods.next()) {
if (invoiceDate.compareTo(rsPeriods.getDate(1))>=0 && invoiceDate.compareTo(rsPeriods.getDate(2))<=0){
//increment period id counter
periodId=uniqnum.GetUniqueNumber("PeriodId="+ rsPeriods.getDate(1) + "-"
+ rsPeriods.getDate(2), 1, 999999999,new Integer(lastCompId));
break; //we found the period we need
}