Solved

Crystal Reports - Duplicate records

Posted on 2009-04-14
11
1,368 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 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

22 Experts available now in Live!

Get 1:1 Help Now