Hello,
(Crystal Reports 2008 with SQL Server)
Working on a report which shows customer appointments grouped by technician (the person who provided the service). In the detail, would like to include a count of appointments in the last 30 days for each customer based their Account Status (1=Open, 2=Closed). For Open accounts, would like a count of appointments in the last 30 days from current date. For Closed accounts, would like a count of appointments in the last 30 days from the account closed date (EndDate). Created the following formula field:
if
{tblCustomer.AccountStatusID} = 1 and CurrentDate in Aged0To30Days
then
DistinctCount ({tblAppointments.ApptID})
else if
{tblCustomer.AccountStatusID} = 2 and {tblAppointments.EndDate} in Aged0To30Days
then
DistinctCount ({tblAppointments.ApptID})
else
0
However, it returns the same number for all each client row. Can if/then/else be used in Running totals?
Attempted to write SQL to do the counts, with no success (syntax errors).
(
SELECT {"tblAppointments"."ApptID"}
Case when {"tblCustomer"."AccountStatusID"} = 1
then DistinctCount({"tblAppointments"."ApptID"}) BETWEEN {fn NOW()} AND {fn NOW()}-30
Case when {"tblCustomer"."AccountStatusID"} = 2
then DistinctCount({"tblAppointments"."ApptID"}) BETWEEN ({"tblAppointments"."EndDate"} AND ({"tbleAppointments"."EndDate"}-30
else 0
FROM "tblAppointments"
WHERE "tblCustomer"."CustID" = "tblAppointments"."CustId"
ORDER BY "tblAppointments"."CustID"
)
Please let me know if more information is needed. Any direction is much appreciated.
Thanks,
DA
(Crystal Reports 2008 with SQL Server)
Working on a report which shows customer appointments grouped by technician (the person who provided the service). In the detail, would like to include a count of appointments in the last 30 days for each customer based their Account Status (1=Open, 2=Closed). For Open accounts, would like a count of appointments in the last 30 days from current date. For Closed accounts, would like a count of appointments in the last 30 days from the account closed date (EndDate). Created the following formula field:
if
{tblCustomer.AccountStatusID} = 1 and CurrentDate in Aged0To30Days
then
DistinctCount ({tblAppointments.ApptID})
else if
{tblCustomer.AccountStatusID} = 2 and {tblAppointments.EndDate} in Aged0To30Days
then
DistinctCount ({tblAppointments.ApptID})
else
0
However, it returns the same number for all each client row. Can if/then/else be used in Running totals?
Attempted to write SQL to do the counts, with no success (syntax errors).
(
SELECT {"tblAppointments"."ApptID"}
Case when {"tblCustomer"."AccountStatusID"} = 1
then DistinctCount({"tblAppointments"."ApptID"}) BETWEEN {fn NOW()} AND {fn NOW()}-30
Case when {"tblCustomer"."AccountStatusID"} = 2
then DistinctCount({"tblAppointments"."ApptID"}) BETWEEN ({"tblAppointments"."EndDate"} AND ({"tbleAppointments"."EndDate"}-30
else 0
FROM "tblAppointments"
WHERE "tblCustomer"."CustID" = "tblAppointments"."CustId"
ORDER BY "tblAppointments"."CustID"
)
Please let me know if more information is needed. Any direction is much appreciated.
Thanks,
DA