SELECT cdr && cdr is call records in previous SET ORDER TO _Primary &&your Primary key *or INDEX ON UniqueID TAG _UNI &&whatever makes a record unique SET EXACT OFFNo problem here, CDR.DNIS and CDR.StartDT (Datetime field as character field)will be my unique id
SELECT; Cur2.UniqueID AS CDR_Uni,; &&something that makes a record in cdr unique, just the same as above Cur1.DEST AS CDR_Dest,; Cur1.CODE AS CDR_Code,; Cur1.Rate AS CDR_Rate,; Cur2.Duration AS CDR_Duration,; IIF(Cur2.Duration >0,; IIF(Cur2.Duration<Cur1.MinimumSec,; (Cur1.MinimumSec/60), (CEILING(Cur2.Duration/Cur1.INCREMENT)/60*Cur1.INCREMENT)),; 0) AS CDR_billdur,; IIF(Cur2.Duration > 0,Cur1.Rate*Cur2.billdur,0) AS CDR_Charge; &&MayBe You need do that down in the replace because of first normalising BillDur FROM Rate AS Cur1,;Here's where I get confused, are you just making empty fields for the rate table data, or are we somehow pulling all the rate.code(s) that match the DNIS(s)?
INNER JOIN cdr AS Cur2; ON ALLTRIM(Cur2.dnis)=Cur1.CODE; AND !EMPTY(Cur2.DEST); INTO CURSOR curHelp *this gives Code "0115411" as well as "01154" for dnis="0115411555555"
*************** new part ************************** now lets see how get rid of it SELECT; Cur1.CDR_Uni,; Cur1.CDR_Code,; MAX(LEN(ALLTRIM(Cur1.CDR_Code); FROM curHelp; INTO CURSOR curSum; GROUP BY 1,2 *only the longest codes for a CDR_Uni should survive SELECT; Cur1.CDR_Uni,; Cur1.CDR_Dest,; Cur1.CDR_Code,; Cur1.CDR_Rate,; Cur1.CDR_Duration,; Cur1.CDR_billdur,; Cur2.CDR_Charge; FROM curHelp AS Cur1,; INNER JOIN curSum AS Cur2; ON Cur2.CDR_Uni==Cur1.CDR_Uni; AND Cur2.CDR_Code==Cur1.CDR_Code; INTO CURSOR curHelp1 *now we should have the rates for the longest possible code *************** /new part ************************** SET RELATION TO CDR_Uni INTO CDR *This is a 1 To 1 relation so no need to SET SKIP REPLACE; CDR.Rate WITH CDR_Rate,; CDR.DEST WITH CDR_Dest,; CDR.CODE WITH CDR_Code,; CDR.BillDur WITH CDR_BillDur,; CDR.Charge WITH CDR_Charge; ALL SET RELATION TO USE USE IN curSum USE IN curHelp SELECT cdr SET ORDER TO