Class CustTransQueryAgingBucktetStat: str dateNull; Range rangeDocDate; date sqlFromDate; date sqlToDate; str date2SqlStr(date _date) { str sqlDate; if (_date == dateNull()) { sqlDate = '01\\01\\1901'; } else { if(_date == maxdate()) { sqlDate = '31\\12\\2150'; } else { sqlDate = date2str(_date, 123, 2, 3, 2, 3, 4); sqlDate = strReplace(sqlDate, '-', '\\'); } } return sqlDate; } ; range = transDataSource.addRange(fieldnum(CustTrans, RecId)); sqlFromDate = statementEndDate ? statementStartDate : dateNull(); sqlToDate = statementEndDate ? statementEndDate : maxdate(); dateNull = date2StrXpp(dateNull()); rangeDocDate = '((DocumentDate >= ' + date2SqlStr(sqlFromDate) + ') &&'; rangeDocDate += '(DocumentDate <= ' + date2SqlStr(sqlToDate) + ')) ||'; rangeDocDate += '((DocumentDate = ' + dateNull + ') &&'; rangeDocDate += '(TransDate >= ' + date2SqlStr(sqlFromDate) + ') && '; rangeDocDate += '(TransDate <= ' + date2SqlStr(sqlToDate) + '))'; range.value(rangeDocDate);