Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Too many or too few rows returned... Post Reply Post New Topic
Author Message
dougietee
Newbie
Newbie


Joined: 14 Jun 2012
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote dougietee Replybullet Topic: Too many or too few rows returned...
     Posted: 19 Jun 2012 at 6:46am
Hi, rookie alert. I'm not even sure if I'm asking this in the right forum.

I hop you don't mind me diving straight in with a question?

I am trying to design a report comprising of data from our CRM database, there are 4 tables being used all linked by an "accountno" field.
CONTACT1 - contains name and address info [one record per person]
CONTACT2 - contains additional contact fields and user defined fields [one record per person]
CONTHIST - contains several history records of various activities for each contact record in CONTACT1 [many per person]
CONTSUPP - contains supplemental contact records and other supplemental data for each contact record in CONTACT1 [many per person]

The report I'm trying to make needs to select 1 of 3 types of record from CONTHIST on 3 different dates and display the results in a row alongside corresponding data from CONTACT1 and 2 and also find and display a specific entry from CONTSUPP.

Like this:


Name | Referrer | Relationship | 2012 | 2011 | 2010 | GA | Email
 C1  |   C2     |      C2      |  CH  |  CH  |  CH  | C2 |  CS


The 2012 2011 2010 fields are the attendance status of a person at an event we hold each year. Values can be ATT DNA and INV. It's possible for a person to have  one of these values for each of the three years.

I have tried two ways of displaying the report. 1. Put the fields in the details section: this returns many rows per person and per year which isn't desired.
2. Put all the fields in the Group header 1 sorted by contact name and suppress the details section: this gives a better looking result but only seems to return one value for one of the years (when I know there are values for the other years too).

I am using the following select formula:
{CONTHIST.ONDATE} in [Date (2010, 04, 13), Date (2011, 04, 11), Date (2012, 04, 17)] and
{CONTHIST.REF} startswith "Name of our event"


I'm using 3 formulas to get the results for each year field. Like this:
if
{CONTHIST.ONDATE}=Date (2010,04 ,13 ) and
{CONTHIST.ACTVCODE}="MDO"
then
Trim ({CONTHIST.RESULTCODE})

the other two formulas have different dates.

I hope I've explained that clearly enough. Does anyone out there know what I'm doing wrong? I think my problem lies in the fact that the CONTHIST table has several records of different types per person, but I assumed that if I used a formula to isolate just the row I was after it would work.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Jun 2012 at 11:20am
There are several ways to do this but I think the easiest way to get this in the format you're looking for will be to add additional copies of CONTHIST to your report and filter each one on a specific date instead of filtering one copy of CONTHIST on multiple dates.  To do this, follow these steps:
 
1.  In the Database Expert, add CONTHIST to the report again.  When you try to add a table that's already in the report,  Crystal will notify you that it's there and will ask if you want to alias it.  Then it will add the table with a suffix of "_1" on the table name.  So you'll see CONTHIST_1 in your list of selected tables.
 
2.  Add CONTHIST again to get CONTHIST_2.
 
3.  Link to these two tables like you're linking to CONTHIST.
 
4.  Modify your selection critera to something like the following:
 
 
{CONTHIST.ONDATE} = Date (2010, 04, 13) and
{CONTHIST.REF} startswith "Name of our event" and
{CONTHIST_1.ONDATE} = Date (2011, 04, 11) and
{CONTHIST_1.REF} startswith "Name of our event" and
{CONTHIST_2.ONDATE} = Date (2012, 04, 17) and
{CONTHIST_2.REF} startswith "Name of our event"
 
5.  Modify your report to us the RESULTCODE field from each of the three CONTHIST tables instead of your formulas. (Based on your sample formula, you may have to either tweak your selection criteria or use a formula instead of the field in order to get the {CONTHIST.ACTVCODE}="MDO" part of your formula.)
 
-Dell
IP IP Logged
dougietee
Newbie
Newbie


Joined: 14 Jun 2012
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote dougietee Replybullet Posted: 19 Jun 2012 at 11:13pm
Thank you so much. I'll give that a try.
IP IP Logged
dougietee
Newbie
Newbie


Joined: 14 Jun 2012
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote dougietee Replybullet Posted: 20 Jun 2012 at 3:42am
Well that seems to work quite well, I've only cross-referenced a few records so far but the data returned for the 3 years seems accurate. It has however broken my formula for extracting the primary email address from the CONTSUPP table. It's returning some email addresses but not others. Why might this be?

Again, I'm using a formula to isolate the correct record in CONTSUPP
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 20 Jun 2012 at 3:59am
What is the formula that you're using for the email?
 
-Dell
IP IP Logged
dougietee
Newbie
Newbie


Joined: 14 Jun 2012
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote dougietee Replybullet Posted: 20 Jun 2012 at 4:15am
GM email address formula:

if {@Primary email} = "1" and
{CONTSUPP.RECTYPE} = "P" and
{CONTSUPP.CONTACT} = "E-mail Address"
then Trim ({CONTSUPP.CONTSUPREF}) else "no primary"


Primary email formula:

Mid ({CONTSUPP.ZIP},2 ,1 )


For some reason I couldn't work the primary email bit into the main formula without getting errors.


As I'm primarily selecting my data based on the CONTHIST table should that be my first table in Database Expert Links?





Edited by dougietee - 20 Jun 2012 at 4:25am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 20 Jun 2012 at 4:35am
Since it doesn't look like you need any other records from CONTSUPP except the email, I would add something like the following into the selection criteria:
 
(IsNull({CONTSUPP.ACCOUNTNO}) or (
Mid({CONTSUPP.ZIP, 2, 1) = '1' and
{CONTSUPP.RECTYPE} = 'P' and
{CONTSUPP.CONTACT} = 'E-mail Address'))
 
Note the parentheses in red - these are important for getting this to work correctly.
 
Your formula for the email address would then be:
 
if IsNull({CONTSUPP.CONTSUPREF}) then 'no primary'
else Trim({CONTSUPP.CONTSUPREF})
 
 
-Dell


Edited by hilfy - 20 Jun 2012 at 4:37am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum