2

I have a little problem with if statement as it populates only last elseif

%%[IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
        SET @WhichNom1 = "1"
        SET @WhichNom2 = "2"

ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
        SET @WhichNom1 = "1"
        SET @WhichNom2 = "3"

ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
        SET @WhichNom1 = "1"
        SET @WhichNom2 = "3"
]%%
@WhichNom1
@WhichNom2
%%[ENDIF]%%

The code above will display two variables when the last ELSEIF is TRUE. What do I need to do to check 3 statements and display WhichNom1 and WhichNom2 for every scenario?

TylerH
  • 20,799
  • 66
  • 75
  • 101
dan123
  • 43
  • 1
  • 1
  • 5

3 Answers3

4

You're only printing the variables if the last elseif is true.

Move them like this:

...    
ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN

        SET @WhichNom1 = "1"
        SET @WhichNom2 = "3"
]%%
%%[ENDIF]%%

@WhichNom1
@WhichNom2

So they're outside the IF/ELSEIF. That way they'll always be printed, but the variables will be set differently based on the clauses.

EDIT:

If you only want the variables printed if one of the statements is true, then you would (as you have mentioned) need to print them within the if statement, OR you could:

SET @WhichNom1 = ""
SET @WhichNom2 = ""

before the if statements, then after them do:

IF @WhichNom1 != "" THEN @WhichNom1
IF @WhichNom2 != "" THEN @WhichNom2

so you only print them if they've been set to something other than "".

  • 1
    Yes, I know, but these two variables have to display only if one of the conditions above is true. Is there an other way to do this rather than printing variables 3 times, under every condition? – dan123 Jul 18 '14 at 11:00
  • 1
    I managed to get it sorted in slightly different way using to IF statements. I will post it as soon as I can reply to my own post otherwise I can't include a code – dan123 Jul 18 '14 at 16:00
2

I managed to get it sorted in slightly different way using two IF statements

%%[IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "2"
SET @Status = "T" 

ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
SET @Status = "T" 

ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "2"
SET @WhichNom2 = "3"
SET @Status = "T" 

ELSE

SET @Status = "F" 

ENDIF]%%

%%[IF @Status == "T" THEN]%%
@WhichNom1
@WhichNom2
%%[ENDIF]%%
TylerH
  • 20,799
  • 66
  • 75
  • 101
dan123
  • 43
  • 1
  • 1
  • 5
0

Rob is correct. Also if you want to print @WhichNom1 and @WhichNom2 outside of the AMPscript block, you'll probably need to code as:

%%[
IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "2"
SET @Status = "T" 

ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
SET @Status = "T" 

ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "2"
SET @WhichNom2 = "3"
SET @Status = "T" 

ELSE

SET @Status = "F" 

ENDIF
]%%

%%[ IF @Status == "T" THEN ]%%

%%= v(@WhichNom1) =%%<br />
%%= v(@WhichNom2) =%%

%%[ ENDIF ]%%
Jackson Chen
  • 111
  • 4
  • 2
    Please make your question all-inclusive. If Rob removes his answer somewhere down the line, then this answer will not be of much use! – Conduit Oct 22 '14 at 21:00