I have a query that I am using in a crystal report to do the WTD, MTD, and YTD. I would like to get rid of doing that in Crystal and do it in the SQL instead.
The columns I would like to see in the report are
Site
Location Name
Type
Amount Posted Yesterday
# of Accounts Yesterday (Distinct Count)
WTD Amount
WTD Accounts (Distinct)
MTD Amount
MTD Accounts (Distinct)
YTD Amount
YTD Accounts (Distinct)
What would best sum the PR_Amount into these buckets?
Code:
SELECT
A.ACCTCPCODE "Site",
L.LOCNAME "Location_Name",
A.ACCTCODE "Account",
CASE
WHEN (C.TYPE='C') THEN 'Charges'
WHEN ((C.TYPE='P') AND (C.PRCODE IN ('90','92'))) THEN 'Patient Payments'
WHEN ((C.TYPE='P') AND (C.PRCODE='93')) THEN 'Credit Card Payments'
WHEN ((C.TYPE='P') AND (C.PRCODE NOT IN ('90','92','93','99'))) THEN 'Payments'
WHEN ((C.TYPE='P') AND (C.PRCODE='99')) THEN 'Refund Payments'
WHEN (C.TYPE='A') THEN 'Adjustments'
ELSE C.TYPE END "Type",
C.PRAMOUNT "PR_Amount",
to_date(C.ORIGPOSTDATE,'j') "Post_Date"
FROM
MEDACCOUNT A
JOIN MEDCHARGES C ON ((A.ACCTCPCODE=C.CPCODE) AND (A.ACCTCODE=C.ACCOUNT) AND (C.SPLITFLAG IS NULL))
LEFT JOIN MEDLOCATIONS L ON ((C.CPCODE=L.LOCCPCODE) AND (C.DOCLOC=L.LOCCODE))
WHERE
(A.ACCTCPCODE IN ('116001','116002','116003'))
AND C.PRCODE not in ('4084F', '3120F', '2010F', '3028F', '2014F', '4045F')
AND (C.ORIGPOSTDATE >= to_char(TRUNC(SYSDATE, 'YYYY'),'j'))
The columns I would like to see in the report are
Site
Location Name
Type
Amount Posted Yesterday
# of Accounts Yesterday (Distinct Count)
WTD Amount
WTD Accounts (Distinct)
MTD Amount
MTD Accounts (Distinct)
YTD Amount
YTD Accounts (Distinct)
What would best sum the PR_Amount into these buckets?