Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Count by Conditions with data from different table Post Reply Post New Topic
Author Message
crstar
Newbie
Newbie


Joined: 02 Aug 2012
Online Status: Offline
Posts: 31
Quote crstar Replybullet Topic: Count by Conditions with data from different table
     Posted: 02 Aug 2012 at 10:43pm
I am newbie in Crystal Report.
 
I have created a stored procedure (Name:SP1) to return value.
Example of value return:
ID  Data1
-------------------------
1   A
1   B
1   C
1   D
1   E
 
I have to map with another table (Name: TB1).
Example of table data:
ID   Data2
--------------------------------------
1   B
1   C
 
At database connection, I link SP1 to TB1 (left outer join), pull out the result by row data as below:
 
 
ID   Data1   Data2
----------------------------------------------------------
1    A                          
1    B           B             
1    C           C             
1    D                          
1    E                          
 
I would like to add a Count column.
 
 
Expected result:
 
ID   Data1   Data2    Count
----------------------------------------------------------
1    A                            0
1    B           B              1
1    C           C             1
1    D                           0
1    E                           0
 
 
If TB1.Data2 able map with SP1.Data1, i require to get the count = 1
  
I try on formula for count:
IF {SP1.Data1}={TB1.Data2} THEN
1
else
0

 
But it wont return 0, only return 1.. like below:
 
ID   Data1   DataMap   Count
----------------------------------------------------------
1    A                           
1    B           B              1
1    C           C             1
1    D                          
1    E                          
 
may i know what should i do to display the 0 as well? is the "IF {SP1.Data1}={TB1.Data2}"  correct?
 
Thanks alot


Edited by crstar - 02 Aug 2012 at 10:55pm
IP IP Logged
saoco77
Senior Member
Senior Member


Joined: 26 Jun 2007
Online Status: Offline
Posts: 104
Quote saoco77 Replybullet Posted: 03 Aug 2012 at 4:29am
Didn't test it but think it should work.

IF isnull({TB1.Data1}) THEN
0
else if {SP1.Data1}={TB1.Data2}
THEN 1

Hope this helps,
Sarah
IP IP Logged
saoco77
Senior Member
Senior Member


Joined: 26 Jun 2007
Online Status: Offline
Posts: 104
Quote saoco77 Replybullet Posted: 03 Aug 2012 at 4:31am
Reading your post again. I think it should actually be

IF isnull({TB1.Data2}) THEN
0
else if {SP1.Data1}={TB1.Data2}
THEN 1
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2012 at 3:42am

you can also change the drop down option in the formula editor to 'default values for nulls' rather than 'exceptions for nulls'.

IP IP Logged
crstar
Newbie
Newbie


Joined: 02 Aug 2012
Online Status: Offline
Posts: 31
Quote crstar Replybullet Posted: 06 Aug 2012 at 2:35pm

its solved!! thanks alot to expert here :)

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