Reputation: 9
I'm trying to figure out how to loop through a table and execute and email once a field changes. So, in the table, I have the following...
Name Num Flag ID Email
A12 1 A 42 [email protected]
A13 1 A 42 [email protected]
A15 1 A 85 [email protected]
Now, the number of rows can be WAY BIGGER or much smaller. I'm trying to figure out how to create a loop, in peoplecode, that will allow me to send "steve" an email once I hit a row with a different email. The table is ordered so I don't have to worry about those issues.
Any assistance or thoughts on planning this are greatly appreciated!
Upvotes: -1
Views: 171
Reputation: 1
Have you considered aggregating your result set?
For example, this would give you a result set that only has one row for each distinct email:
SELECT Email
FROM yourTable
GROUP BY Email
If there are additional fields you need to distinquish records by, you can add them to the group by clause.
If the result set you are using already has a lot of filtering, you might consider something like putting it into a temp table, and then selecting the aggregated emails from that temp table.
Upvotes: 0