# Personalized email with loop dataset activity

**URL:** <https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456>\
**Category:** Toad Data Point & Toad Intelligence Central\
**Created:** [June 10, 2015, 8:46am UTC](https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456 "2015-06-10T08:46:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy.corson](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andy.corson](https://forums.toadworld.com/u/andy.corson)\
**Post date:** [June 10, 2015, 8:46am UTC](https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456/1 "2015-06-10T08:46:21Z")

</div>

I have a table that stores distribution list, first name, last name, email address, and I would like to create a loop activity that pulls in first name and email address for a specific list. So my query is as follows:

SELECT distribution\_list, f\_name, l\_name, email  
FROM dept\_db.dbo.rpt\_distribution\_list  
WHERE distribution\_list = ‘Test’

I would like the email activity to send an email to each address on the list using a variable for email, and then include the first name in the body of the email using another variable. I think that I have to put the above query into the SQL Script section of the loop activity. I tried putting in a set variable and email activity within the Loop\_row\_1 section of the loop, but this didn’t work. Can anyone show me how to set up such a script?

---

<div class="post-metadata">

**Author:** ![GregDavis11009](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gregdavis11009/32/122_2.png) [@GregDavis11009](https://forums.toadworld.com/u/GregDavis11009)\
**Post date:** [June 10, 2015, 9:12am UTC](https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456/2 "2015-06-10T09:12:07Z")

</div>

what version of TDP are you using? There is a Set Variable and Set Variable Value, that work differently from each other in the higher versions of TPD. If you create the variable outside of the loop you must use Set Variable Value to update that value inside of the loop or it will create a new variable with the same name inside of the loop with a scope of just inside the loop. When you set your FirstName variable inside the loop set it to [tag:LoopResultName].F\_Name#. Your loop query basically returns a table and then steps through it one row at a time.

---

<div class="post-metadata">

**Author:** ![andy.corson](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andy.corson](https://forums.toadworld.com/u/andy.corson)\
**Post date:** [June 10, 2015, 9:21am UTC](https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456/3 "2015-06-10T09:21:25Z")

</div>

Thanks Greg. I was able to get it to work.

---

<div class="post-metadata">

**Author:** ![GregMoore](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gregmoore/32/302_2.png) [@GregMoore](https://forums.toadworld.com/u/GregMoore)\
**Post date:** [June 10, 2015, 11:31pm UTC](https://forums.toadworld.com/t/personalized-email-with-loop-dataset-activity/33456/4 "2015-06-10T23:31:31Z")

</div>

Hi Toad World
