I have a field called travelinterestand data extension name called testforelavaran. i dont know how many values in that field, suppose if that field contains four values, (col1,col2,col3,col4) and i want to count the values using rowcount, by using for loop and i will concatenate all the four values by using semicolon

I have tried:

var @travelinterest, @rows, @rowCount,@interestsTemp
set @rows = LookupRows("testforelavaran","travelinterest", @lookupValue)
set @rowCount = rowcount(@rows)
for @i = 1 to @rowCount
set @interestsTemp = concat(

but it is not working, please help me with AMPScript code,

My output will be - output value is %%(travelinterest)%% (col1;col2;col3;col4)

  • What error is it giving?
    – 0xsegfault
    Commented Jul 10, 2017 at 15:09

1 Answer 1


You can't reference row-set elements like that in AMPScript. You'll have to do something like this:


var @lookupValue, @travelinterest, @rows, @rowCount, @interestsTemp
set @lookupValue = AttributeValue("WHATEVERLOOKUPVALUEHERE")
set @rows = LookupRows("testforelavaran","WHATEVERLOOKUPCOLUMNHERE", @lookupValue)
set @rowCount = rowcount(@rows)
set @interestsTemp = ""

if rowCount > 0 then

    for @i = 1 to @rowCount
        set @row = row(@rows,1)
        set @travelinterest = field(@row,"travelinterest")
        output(concat("<br>@i: ", @i, ", @travelInterest: ", @travelInterest))
        set @interestsTemp = concat(@interestsTemp,";",@travelinterest)
    next @i


You must log in to answer this question.