0

I am using LookupRows to grab some data from a data extension and use in an email. I'd like to grab data from another data extension as well but can't get it to work. Is this possible? If so, can someone give me some tips?

Here is my current AMPScript. Contact_1 is the data extension. I'd like to do a look up on Contact_2 for the field ref333.

%%[
set @contactid = [Contact ID]

set @contactRows = LookupRows("Contact_1","_ContactKey",@contactid)
set @contactRowCount = Rowcount(@contactRows)

  if @contactRowCount > 0 then
      set @REF1 = Field(Row(@contactRows, 1),"ref111")
      set @REF2 = Field(Row(@contactRows, 1),"ref222")
  endif

]%%

EDIT - what I tried was adding this:

set @contactRows2 = LookupRows("Contact_2","_ContactKey",@contactid)
set @contactRowCount2 = Rowcount(@contactRows2)

  if @contactRowCount2 > 0 then
      set @REF3 = Field(Row(@contactRows2, 1),"ref333")
  endif

I got a huge amount of errors with this.

1
  • can you share the errors you are receiving? Commented Aug 3, 2017 at 16:05

1 Answer 1

4

Should be pretty easy, just need to do 2 lookups:

%%[
set @contactid = AttributeValue("Contact ID") /* Better handling of NULL values */

set @contactRows = LookupRows("Contact_1","_ContactKey",@contactid)
set @contactRows2 = LookupRows("Contact_2","_ContactKey",@contactid)

set @contactRowCount = Rowcount(@contactRows)
set @contactRowCount2 = Rowcount(@contactRows2)

  if @contactRowCount > 0 AND @contactRowCount2 > 0 then
      set @REF1 = Field(Row(@contactRows, 1),"ref111")
      set @REF2 = Field(Row(@contactRows, 1),"ref222")
      set @REF3 = Field(Row(@contactRows2, 1),"ref333")
  endif

]%%

or if you want the two rowcounts independently, you can use the following:

%%[
set @contactid = AttributeValue("Contact ID") /* Better handling of NULL values */

set @contactRows = LookupRows("Contact_1","_ContactKey",@contactid)
set @contactRows2 = LookupRows("Contact_2","_ContactKey",@contactid)

set @contactRowCount = Rowcount(@contactRows)
set @contactRowCount2 = Rowcount(@contactRows2)

  if @contactRowCount > 0 then
      set @REF1 = Field(Row(@contactRows, 1),"ref111")
      set @REF2 = Field(Row(@contactRows, 1),"ref222")

      if @contactRowCount > 0 AND @contactRowCount2 > 0 then
          set @REF3 = Field(Row(@contactRows2, 1),"ref333")
      else
          set @REF3 = ""
      endif 
  endif

]%%

You must log in to answer this question.

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