Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Formula to display records not in table? Post Reply Post New Topic
Author Message
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet Topic: Formula to display records not in table?
    Posted: 21 Jul 2011 at 7:08am
I am selecting records based on head of household/spouse, but I want to still include records that have no spouse at all.

The following record selection formula returns all head of household records:
(relationship-headofhousehold)=FALSE

However, it eliminates anyone without a spouse.  I have tried something like this to make it work:

(relationship-headofhousehold)=FALSE OR (spouse link) = ' ' (or 0)

Nothing ever works when I try this.  I either end up with no records, or I end up only with records that actually have a spouse.

In general, the question is: How do I specify records I want to see within a table, but also show records that are not even in the table I am selecting on?

Any help is greatly appreciated, again.


Edited by JFinzel - 21 Jul 2011 at 7:10am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 21 Jul 2011 at 7:43am
if you have 2 tables, and you want all of one table and part of another, use an outer join (left or right, I don't know how CR defines them). 
If you are looking for 2 different pieces of information in the same table....joining straight to the tables, I am not sure...you should be able to do an OR in the filtering criteria, or a self-join or Union if using a stored proc.
 
I am not familiar with any of the sql selects in CR as all my reports gather their data from Stored Procs.
 
If the data is truly not in the table, then you can't get it.  CR only reads that data that is there, and either includes or excludes it from the report.
 
HTH


Edited by lockwelle - 21 Jul 2011 at 7:44am
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet Posted: 21 Jul 2011 at 8:44am
Let me see if I understand you correctly.

Suppose my main constituent table goes up to number 483.
I also have a table that has spouses.  This table goes to 456.

I want to find people who are in table 1, but have no spouse in table 2.

I also need to find who is head of household from table 1, but I already know how to do this with another condition and table that I have.

Are you saying that I can't get the information by doing a formula like so:
(Const. is in table 1) and (Const.Spouse is not in table 2) [i.e. Const. has no record in table 2 for spouse]

?

I have already run into many cases where this would be helpful.  Is it not possible to do a formula like this?

Thank you!


Edited by JFinzel - 21 Jul 2011 at 8:51am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 21 Jul 2011 at 11:13am
if the numbers 'identify' the rows, so number 1 in both table refer to the same 'couple', then you can do outer join.
 
In SQL it would be select * from table1 as t1
  left outer join table2 as t2
    on t1.number = t2.number
where t2.number is null
 
this is return all rows in table1, and any matching rows from table2.  If there is not a match in table2, then the value is NULL.
 
you can link tables in CR, and there is the ability to do an outer join (right click on the link line).  I don't know how CR determines left and right.
 
without the link, or using an inner join, then the formula that you propose won't work.  With link, it would be ISNULL(Const.Spouse)  (because it returns True if the spouse is missing ie null, and false if they exist)
 
HTH
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.