SQL - New Clients by Date
v7,v6
See Create Export to CSV using SQL Query for information on using query below for export to csv.
select dateadd(-extract(weekday from BM."Dis_Date") day to BM."Dis_Date") as "Week Starting",
count(distinct BM."Ref_Number") as "New Clients"
from "General_Ledger_Log" GL
left outer join "Bill_Main" BM on GL."Trn_Ref"=BM."Ref_Number"
where GL."Trn_Source"='D' and
GL."Trn_Type"='B' and
GL."Trn_Ref_Type"='I' and
GL."Prd_Class" in ('S', 'F', 'R', 'M', 'D', '$', 'B') and
GL."Trn_Date" >= :DateLo/*Start Date*/ and
GL."Trn_Date" <= :DateHi/*Finish Date*/ and
(0 = :BranchALL/*Branch*/ or GL."Trn_Branch" = :BranchALL/*Branch*/) and
coalesce(GL."Dont_Report", null, '') <> 'Y' and
BM."New_Client" = 'Y'
group by 1