AMPScript中的IF语句

时间:2014-07-18 09:39:44

标签: if-statement exacttarget ampscript

我对if语句有一点问题,因为它只填充最后一个

%%[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]%%

当最后一个ELSEIF为TRUE时,上面的代码将显示两个变量。我需要做些什么来检查3个语句并为每个场景显示WhichNom1和WhichNom2?

由于 丹

3 个答案:

答案 0 :(得分:3)

如果最后一个elseif为真,你只会打印变量。

像这样移动它们:

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

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

@WhichNom1
@WhichNom2

所以他们不在IF / ELSEIF之外。这样他们将始终打印,但变量将根据子句设置不同。

编辑:

如果您只想在其中一个陈述为真的情况下打印变量,那么您(如您所述)需要在if语句中打印它们,或者您可以:

SET @WhichNom1 = ""
SET @WhichNom2 = ""
在if语句之前,然后在它们之后执行:

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

因此,如果他们已被设置为""以外的其他内容,则只打印它们。

答案 1 :(得分:2)

我设法使用两个IF语句以稍微不同的方式对其进行排序

%%[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]%%

感谢您的帮助Rob!

答案 2 :(得分:1)

罗布是对的。此外,如果您想在@WhichNom1块之外打印@WhichNom2AMPscript,您可能需要编码为:

%%[
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 ]%%