I am currently using an ampscript function in Marketing Cloud to check if the DMAID field for a record in my sendable data extension is empty. If it is empty, some default content will be pulled in. If not, then this block of Ampscript will run:

%%[var @rs, @row, @cntr SET @rs = LookupRows("DE_2", "MARKET", DMAID) for @cntr = 1 to RowCount(@rs) do SET @row = Row(@rs, @cntr)]%% 

%%=Field(@row, "END_TAGS")=%% 

%%[next @cntr]%%

This code loops through DE_2 and uses the LookupRows function to see if any value in its Market field matches the subscriber's DMAID value in my sendable data extension. If it finds a match, then it will print the "END_TAGS" value corresponding to that Market value.

However, sometimes a subscriber will have a value in their DMAID field, but it doesn't match any Market value in DE_2. If that happens, all that shows up is a blank space. I would like to show the default content if the LookupRows function doesn't find a match, but I can't figure out how to do that. Maybe LookupRows isn't the best function to be using?

I'm very new to ampscript as a whole, so any recommendations are appreciated.

1 Answer 1


@ K K try like this

            var @rs, @row, @cntr
             SET @rs = LookupRows("DE_2", "MARKET", DMAID)
            if Rowcount(@rs) > 0 then
            set @count = Rowcount(@rs)
               for @i=1 to @count do
           set @row=Row(@rs,@i)
            set @endtag=Field(@row, "END_TAGS")

              next @i
              set @endtag='set default';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .