Solved

Crystal Reports - Duplicate records

Posted on 2009-04-14
11
1,366 Views
Last Modified: 2012-06-22
I'm using crystal reports 11. When I execute my report, I'm getting duplicate records. I have narrowed it down to a formula. It's only when the formula is added to the report, it creates many, many duplicates.

Here is my formula:
if {mwsCustFieldDef.MWFieldNum) = 437 and {mwlCustomField.YNValue} = True then "X" else ""

Both of these fields are bit fields.  I had to use True for the YNValue field because I kept getting a boolean is required here. The YNValue field is just 1 and 0.

Any ideas?

The code below is my joins. The problem might be in the joins.
mwlLoanApp.ID Right Outer Join mwlCustomField.LoanApp_ID

mwlCustomField.CustFieldDef_ID Right Outer Join mwsCustFieldDef.ID

Open in new window

0
Comment
Question by:asmyatt
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 24143741
Please post your record selection criteria (Report|Selection Formulas|Record..).

In general, it's definitely possible to get duplicate records when using outer joins, since you'll get one record back for every record that matches the primary table, unless you limit the recordset from the secondary tables.  If we have a better idea of what your report is doing, we might be better equipped to provide a solution.

~Kurt
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24143792
I don't see this at all.
Adding a formula field into a report can't create duplicate records.
There will be the same number of records in the report as there was before you added the formula field.

As for the joins, yes, the problem might lie there.
If there can be multiple mwlLoanApp records for each mwlCustomField record and/or multiple mwlCustomField records for each mwsCustFieldDef record then what you see in the report could appear as duplicate records, depending on the fields that are displayed.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24144258
I tend to agree that in general adding a formula shouldn't change the record selection.  However if one of the fields in the formula is using a field that isn't on the report and is the first field from one of the tables then the join may not have been used until it was needed to get records from the joined table.

mlmcc
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 24145270
Goodness me, I never knew that.

But I've just tested a few cases and proved to myself that  it's true.
It does indeed ignore the joins until you do something in the design that requires them.


So,  asmyatt, you might well be correct in that the formula adds more records into the report. My apologies for misleading you.

But the cause of the problem is still really the joins. As I said before, if you have 1-many links then you will get multiple records per mwsCustFieldDef.ID

You can use grouping and suppression in CR to limit what you see.  If you group on mwsCustFieldDef.ID and in the group header add whatever other fields you want to see, and then suppress the detail section, you will only see on 'record' per mwsCustFieldDef.ID.

However I don't know how your formula field applies in that situation.
If you can have different values of {mwsCustFieldDef.MWFieldNum) and {mwlCustomField.YNValue} for the same
mwsCustFieldDef.ID then how do you decide which to display?
 

0
 
LVL 2

Author Comment

by:asmyatt
ID: 24147878
I've posted the record selection criteria (Report|Selection Formulas|Record.) and then the SQL Query in CR for all the joins. The report selection returns the right number of records, but when I add in the formula it creates the duplicates. Basically in our application we have a custom field we created as a check box. When the user checks the box in the application, it post a 1 in mwlCustomfield.YNValue, but only for mwsCustFieldDef.MWFieldNum = 437. mwlCustomfield.YNValue is also connected to many, many more mwsCustFieldDef.MWFieldNum from 1 - 1000. I think this is causing the duplicates because it sees all the other YNValue = 1 for each record. Does that make sense?
{mwlAppraiserNote.UpdatedOnDate} in dateadd("n",-20,currentdatetime) to currentdatetime and

{mwlLoanData.FinancingType} <> "F" or 

{mwlAppraiserNote.UpdatedOnDate} in dateadd("n",-20,currentdatetime) to currentdatetime and

{mwlLoanData.FinancingType} = "F" and

{mwlLoanApp.CaseNum} <> '""'
 
 

 SELECT DISTINCT "mwlAppraiserNote"."UpdatedOnDate", "mwlLoanApp"."LoanNumber", "mwlLoanData"."FinancingType", "mwlLoanApp"."CaseNum", "mwlAppraiserNote"."ApprCompanyName", "mwlAppraiserNote"."ApprContactName", "mwlSubjectProperty"."Street", "mwlSubjectProperty"."City", "mwlSubjectProperty"."State", "mwlSubjectProperty"."ZipCode", "mwlSubjectProperty"."ShortLegal", "mwlBorrower"."LastName", "mwsCustFieldDef"."MWFieldNum", "mwlCustomField"."YNValue"

 FROM   (((("INTERLINQE3"."dbo"."mwlBorrower" "mwlBorrower" LEFT OUTER JOIN ("INTERLINQE3"."dbo"."mwlSubjectProperty" "mwlSubjectProperty" LEFT OUTER JOIN "INTERLINQE3"."dbo"."mwlLoanApp" "mwlLoanApp" ON "mwlSubjectProperty"."LoanApp_ID"="mwlLoanApp"."ID") ON "mwlBorrower"."LoanAPP_ID"="mwlLoanApp"."ID") LEFT OUTER JOIN "INTERLINQE3"."dbo"."mwlLoanData" "mwlLoanData" ON "mwlLoanApp"."ID"="mwlLoanData"."ObjOwner_ID") RIGHT OUTER JOIN "INTERLINQE3"."dbo"."mwlAppraiserNote" "mwlAppraiserNote" ON "mwlLoanApp"."ID"="mwlAppraiserNote"."ObjOwner_ID") RIGHT OUTER JOIN "INTERLINQE3"."dbo"."mwlCustomField" "mwlCustomField" ON "mwlLoanApp"."ID"="mwlCustomField"."LoanApp_ID") RIGHT OUTER JOIN "INTERLINQE3"."dbo"."mwsCustFieldDef" "mwsCustFieldDef" ON "mwlCustomField"."CustFieldDef_ID"="mwsCustFieldDef"."ID"

 WHERE  (("mwlAppraiserNote"."UpdatedOnDate">={ts '2009-04-15 05:42:42'} AND "mwlAppraiserNote"."UpdatedOnDate"<{ts '2009-04-15 08:22:43'}) AND "mwlLoanData"."FinancingType"<>'F' OR ("mwlAppraiserNote"."UpdatedOnDate">={ts '2009-04-15 05:42:42'} AND "mwlAppraiserNote"."UpdatedOnDate"<{ts '2009-04-15 08:22:43'}) AND "mwlLoanData"."FinancingType"='F' AND "mwlLoanApp"."CaseNum"<>'""')

 ORDER BY "mwlBorrower"."LastName"

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 100

Expert Comment

by:mlmcc
ID: 24151738
You might need to use ( ) to get the order correct in the filter.  

(
{mwlAppraiserNote.UpdatedOnDate} in dateadd("n",-20,currentdatetime) to currentdatetime and
{mwlLoanData.FinancingType} <> "F"
)
 or
(
{mwlAppraiserNote.UpdatedOnDate} in dateadd("n",-20,currentdatetime) to currentdatetime and
{mwlLoanData.FinancingType} = "F" and
{mwlLoanApp.CaseNum} <> '""'
)

mlmcc
0
 
LVL 2

Author Comment

by:asmyatt
ID: 24152242
mlmcc, I 'm getting the correct number of records if you take out the duplicates. I added the () and received the same results.

Thanks.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24153823
Can any of the fields be NULL?

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24153828
I think the problem stems from the fact you are selecting/filtering based on the joined tables.  In that case Crystal converts the joins to INNER

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
ID: 24154232
I agree that it looks like your JOIN's are probably the problem, in one way or another.  However ...

 In your record selection and query you have {mwlLoanApp.CaseNum} <> '""'  (two double-quotes inside two single-quotes).  Are you really looking for the records where that field has two double-quotes in it, or are you looking for the records where that field is empty?  If it's the latter, change the record selection to just use "" or ''.

 James
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24167630
I would have expected some sharing of the points in this Q.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now