我的数据扩展包含6个字段:
EmailAdress (type: EmailAdress, unique)
Field1 (type: number, not nullable)
Field2 (type: number, not nullable)
Field3 (type: number, not nullable)
Field4 (type: number, not nullable)
Field5 (type: number, not nullable)
我有3个目标:
1。将每个字段的值传递给ampscript变量(简单部分)
%%[
Set @var1 = Field1
Set @var2 = Field2
Set @var3 = Field3
Set @var4 = Field4
Set @var5 = Field5
]%%
2。根据值变量对变量进行排序,然后(3)将变量传递给五个内容区域中的一个。
%%=ContentAreaByName("my contents\Campaigns\mainitem\@maxvar1")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem1\@maxvar2")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem2\@maxvar3")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem3\@maxvar4")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem4\@maxvar5")=%%
例如,如果我的字段值为:
Field1: 10
Field2: 15
Field3: 5
Field4: 1
Field5: 100
然后我的五个内容区应填充如下:
%%=ContentAreaByName("my contents\Campaigns\mainitem\@field5")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem1\@field2")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem2\@field1")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem3\@field3")=%%
%%=ContentAreaByName("my contents\Campaigns\subitem4\@field4")=%%
将值传递给amscript值非常容易。但是desc对它们进行排序并将它们传递给合适的@maxvar似乎对我有限的ampscript知识有点延伸。
非常感谢任何帮助!
答案 0 :(得分:0)
很好的问题。我使用Query Activity将您的数据扩展程序取消,然后使用LookupOrderedRows()函数以正确的顺序检索它们。在AMPScript中排序太过分了。
T-SQL UNPIVOT()函数不能在ET / SFMC上工作,因此您需要在查询活动中以旧式方式执行此操作:
select
emailAddress
, field
, fieldValue
from [unpivot-test]
cross apply (
select 'field1', field1 union all
select 'field2', field2 union all
select 'field3', field3 union all
select 'field4', field4 union all
select 'field5', field5
) c (field, fieldValue)
我在my blog上有几个AMPScript查找示例。这是LookupOrderedRows()之一:
%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i
set @lookupValue = "whee"
set @numRowsToReturn = 0 /* 0 means all */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
for @i = 1 to @rowCount do
var @DEColumn1, @DEColumn2
set @row = row(@rows,@i) /*get row based on loop counter */
set @DEColumn1 = field(@row,"DEColumn1")
set @DEColumn2 = field(@row,"DEColumn2")
]%%
Row %%=v(@i)=%%, DEColumn1 is %%=v(@DEColumn1)=%%, DEColumn2 is %%=v(@DEColumn2)=%%
%%[
next @i ]%%
%%[ else ]%%
No rows found
%%[ endif ]%%
此外,在salesforce.stackexchange.com上发布任何未来的ET / SFMC问题,并使用marketing-cloud
标记这些问题。那里有更多的人提问/回答问题。