Skip to content
Advertisement

Group By function

hope you all having a great day. I need some help with this query. Just to explain the situation, I have to send e-mails containing the data found in this select, but I have to group by customers (TBLOTE.CEMPRES) so it would build a single e-mail for each customer found. Example, if the query finds 3+ row for customer ´John Inc.´ and 1 row for ´Jack Corp.´, it should send 2 e-mails, one containing the 3+ rows about John Inc, and the other one containing the 1 row found for Jack Corp. I hope I could be clear enough on my explanation.

Advertisement

Answer

Currently you have 2 loops. The outer loop (cursor C1) loops through all records and the inner loop (cursor c2) loops through the email addresses and sends an email for every iteration. This can be written in pseudo code as:

To satisfy your requirement, add a 3rd loop:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement