Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Multiple IfThenElse Post Reply Post New Topic
Author Message
crystalgal
Groupie
Groupie
Avatar

Joined: 20 Feb 2009
Location: United States
Online Status: Offline
Posts: 66
Quote crystalgal Replybullet Topic: Multiple IfThenElse
     Posted: 22 Nov 2013 at 7:36am
Hello all,
I need a help with the formula for multiple IFThenElse situation:
if answer = '1' then 'I am good'
else if answer = '2' then 'I am better'
else if answer = '3' then 'I am the best'
else if.....
end if;
it is working if students answer is only one but sometimes the answer can be 1 and 2 or 1 and 3 or 1 and 3 etc.
what do I do?

TIA
IP IP Logged
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Posted: 22 Nov 2013 at 8:39am
if {field} = 1 Then "I am good"
Else
If {field} = 2 Then "I am better"
Else
If {field} = 3 Then "I am the best";

or use Case like

Select {field}
Case 1 : "I am good"
Case 2 : "I am better"
Case 3 : "I am the best"
Default : "whatever default expression";


give one of those a shot and see how they do.



*****EDIT******
I didn't notice the last part to account for multiple answers. this will not work for that then. sorry.


Edited by bwsanders - 22 Nov 2013 at 8:45am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 22 Nov 2013 at 10:16am
if this is all on the same row you can concatenate several if-then statements.
(if {field} = 1 Then "I am good " ) + (If {field} = 2 Then "I am better ") +
(If {field} = 3 Then "I am the best ")
 
If this is evaluating multiple rows than you need to use shared variables to concantentate the strings from row to row and then they can be displayed in the a footer (group or report)
 
If you have NULLs you need to set the formual to use default values for Nulls


Edited by DBlank - 25 Nov 2013 at 5:01am
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 23 Nov 2013 at 6:49pm
Hi
 
If you have only one field 'Answer' with a single value then you can't write 'IF' statement using 'AND' because it always go in 'False' state and you will not get any results.
 
If you have multipul fields like  'ANSWER1',ANSWER2,ANSWER3' then it is possible to use conditional statement using 'and'.
 
 
Thanks,
Sastry
IP IP Logged
crystalgal
Groupie
Groupie
Avatar

Joined: 20 Feb 2009
Location: United States
Online Status: Offline
Posts: 66
Quote crystalgal Replybullet Posted: 25 Nov 2013 at 2:42am
Thank you all.
DBlank: can you please give an example of using a shared variable. TIA
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 25 Nov 2013 at 11:41am

lots of examples of these in the forum. These two should get you started.

http://crystalreportsbook.com/forum/forum_posts.asp?TID=19798
http://crystalreportsbook.com/forum/forum_posts.asp?TID=18394
 
 
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