Crystal Reports 2013: How do I select a sub-group of records within a main group of records

Purpose: Create report showing "only" employees having both EARNINGS and DEDUCTIONS for the same pay period.

Data:       Each record in table (PRDT) contains fields with; PayDate, Employee#, RecordType, RecordCode, Amount, Hours.  

Below is my Select Query (tables in addition to PRDT are involved for inclusion of demographic data).
The WHERE CLAUSE has been formated here for purpose of clarity:

 SELECT "PRDT"."PRCo", "PRDT"."PREndDate", "PRDT"."Employee", "PRDT"."EDLType", "PRDT"."EDLCode", "PRDT"."Hours", "PRDT"."Amount", "PRPH"."PaidDate", "PRPC"."BeginDate"
 FROM   ("DataBase1"."dbo"."PRDT" "PRDT" LEFT OUTER JOIN "DataBase1"."dbo"."PRPH" "PRPH" ON (((("PRDT"."PRCo"="PRPH"."PRCo") AND ("PRDT"."PREndDate"="PRPH"."PREndDate")) AND ("PRDT"."Employee"="PRPH"."Employee")) AND ("PRDT"."PRGroup"="PRPH"."PRGroup")) AND ("PRDT"."PaySeq"="PRPH"."PaySeq")) LEFT OUTER JOIN "Viewpoint"."dbo"."PRPC" "PRPC" ON (("PRDT"."PRCo"="PRPC"."PRCo") AND ("PRDT"."PRGroup"="PRPC"."PRGroup")) AND ("PRDT"."PREndDate"="PRPC"."PREndDate")

 WHERE  ("PRDT"."PREndDate">={ts '2015-07-26 00:00:00'} AND "PRDT"."PREndDate"<{ts '2015-07-27 00:00:00'})
               AND  ("PRDT"."PRCo"=6 OR "PRDT"."PRCo"=28)

               AND  ((("PRDT"."EDLCode"=0 OR "PRDT"."EDLCode"=1 OR "PRDT"."EDLCode"=2 OR "PRDT"."EDLCode"=3)
                          AND "PRDT"."EDLType"='E')
                  OR  (("PRDT"."EDLCode"=401 OR "PRDT"."EDLCode"=402 OR "PRDT"."EDLCode"=403 OR "PRDT"."EDLCode"=410)
                          AND "PRDT"."EDLType"='D' AND "PRDT"."Amount">0))

 ORDER BY "PRDT"."PRCo", "PRDT"."Employee"

Image of sample output is attached.
Ted BruningIT ConsultingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To do it in SQL you will have to build a query or stored procedure in the database or use a Crystal Command.

How much data are you getting for a time period.  
I suspect it will be just as fast and easier to use group selection

Create 2 formulas
Name - HasEarnings
If {"PRDT"."EDLType"} ='E' then

Name - Has Deductions
If {"PRDT"."EDLType"} ='D' then

Add a group on Employee (Name or ID), if you don't already have one
Drop the above formulas into the detail section
Right click one of them
CHoose SUM as the type
Put it in the Employee group footer

DO the same for the other one

FOrmula to use is

Sum({@HasEarnings,{EmployeeField}) >= 1
Sum({@Has Deductions,{EmployeeField}) >= 1

Click SAVE (OK)

Run the report

If you are doing an overall summary of earnings and deductions it will include ALL employees not just those with both earnings and deductions.  Group selection is basically suppression.

You can get around that with formulas like the 2 above but have them return the earnings/deductions
Rather than 1.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ted BruningIT ConsultingAuthor Commented:
Hi mlmcc,

Thank you for your timely response. I have modified my report to your suggestion, however the desired result has not occurred.

Image 1
Image 2
Ted BruningIT ConsultingAuthor Commented:
Oops! One little oversight prevented success.

I forgot to reference the {PRDT.Employee} field in the Group Selection formula:

Sum ({@HasEarn})  >= 1
Sum ({@HasDedct}) >= 1

After correcting to:
Sum ({@HasEarn},{PRDT.Employee})  >= 1
Sum ({@HasDedct},{PRDT.Employee}) >= 1

it performed as expected.

Thanks again mlmcc!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.