Solved

Crystal Reports - Duplicate records

Posted on 2009-04-14
11
1,379 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
[NotSupportedException: Not supported within subreports.] 2 78
display n/a in column 2 31
Crystal reports vb.net 2 54
Crystal Reports Licensing Questions 4 34
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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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