Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple 'if-then-else' clauses in a formula

Status
Not open for further replies.

elsenorjose

Technical User
Oct 29, 2003
684
US
Hello everyone,

I need some help formulating an 'if-then-else' clause.

I have a view with several different projects and tasks. Each project and task has an associated start and end date. Depending on the task, I need to choose one of the following:

Project End Date
Task End Date
Task Start + Task End

So far, this part of my formula works:

Code:
If ({usrPDM_QC.taskname} like '*mfg*' 
or {usrPDM_QC.taskname} like 'drug product manufacturing' 
or {usrPDM_QC.taskname} like '*qc*'  
or {usrPDM_QC.taskname} like 'package*'
or {usrPDM_QC.taskname} like 'label*')
then ToText(getLocalTime ({usrPDM_QC.TaskStartDate}),"dd-MMM-yy")+' '+'-'+' '+ToText(getLocalTime ({usrPDM_QC.TaskEndDate}),"dd-MMM-yy")

However, when I try to add another 'If' to test for another set of tasks and only one date, I get an error.

Code:
If ({usrPDM_QC.taskname} like '*mfg*' 
or {usrPDM_QC.taskname} like 'drug product manufacturing' 
or {usrPDM_QC.taskname} like '*qc*'  
or {usrPDM_QC.taskname} like 'package*'
or {usrPDM_QC.taskname} like 'label*')
then ToText(getLocalTime ({usrPDM_QC.TaskStartDate}),"dd-MMM-yy")+' '+'-'+' '+ToText(getLocalTime ({usrPDM_QC.TaskEndDate}),"dd-MMM-yy")
else if {usrPDM_QC.taskname} like 'bulk*' then {usrPDM_QC.ProjEndDate}

I also need to add a 3rd 'else if' to test for one more set of task names but I get an error: 'A string is required here' and the 'if' after the 'else' is highlighted. What do I need to do to make this formula work correctly?

Thank you.

Using CR XI on Windows XP Pro and SQL Server 2005.

 
You didn't mention the error message, but it looks like you are using 2 different datatypes on your if statement output (string then date)

If that is the case then change your first 'else if' statement:

else if {usrPDM_QC.taskname} like 'bulk*' then
totext({usrPDM_QC.ProjEndDate})
 
Thanks Dunlop. I did list the error: 'A string is required here' and the 'if' after the 'else' is highlighted.

I'm assuming that because I am concatenating the two dates for the first clause, the output is converted to string? Good to know for future reference.

Thanks again.
 
Disregard my last post. I'm slow today. Of course I'm outputting a string...I'm doing the conversion in the ToText clause.

 
: )

I misred your error code as only applying to the 2nd else if statement. Glad it worked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top