January 3, 2019 at 6:36 am
would you know how to help with this.
This is the table below
Accountname Firstname Lastname EmployeeNumber ReportsTo Reports To Email SENT_FLAG
SQLA-terry Terry T1234 Terry Jago Terry@one.xxx 0
SQLA-Graham Graham N T12345 Terry Terry@one.xxx0
SQLA-Ryan Ryan T T123456 Ted Terry.test@test.com 0
SQLA-Kelvin Kelvin M T123456 Ted Terry.test@test.com 0BEGIN
currently its sending 4 emails I only want it to send 2.
ie I want one email sent out for these two email addresses
SQLA-terry Terry T1234 Terry Jago Terry@one.xxx 0
SQLA-Graham Graham N T12345 Terry Terry@one.xxx0
to Terry@one.xxx
please see enclosed accounts
SQLA-terry Terry
SQLA-Graham Graham N
Terry
and one email sent out for this
SQLA-Ryan Ryan T
SQLA-Kelvin Kelvin M
ie
to Terry.test@test.com
please see enclosed accounts
SQLA-Ryan Ryan T
SQLA-Kelvin Kelvin M
ted
Thanks for the help in advance.
Terry
January 3, 2019 at 6:59 am
It looks like you may need to refine the query to something like:
SELECT DISTINCT manager_email FROM table
Then the body of the email may need an addition CURSOR to build the table for each employee.
Or is there something else going on?
January 3, 2019 at 7:08 am
at the moment I get 4 emails two are correct and two are blank I thought with the delete I would only get one email per email address.
I would like one email with this
to Terry.test@test.com
please see enclosed accounts
SQLA-Ryan Ryan T
SQLA-Kelvin Kelvin M
ted
and one with this
to Terry@one.xxx
please see enclosed accounts
SQLA-terry Terry
SQLA-Graham Graham N
Terry
January 3, 2019 at 7:20 am
Just some pseudo-code here:
DECLARE curEmail CURSOR FOR
SELECT DISTINCT manager_email FROM table
OPEN & FETCH into @email
-- create body
SET @body = 'please see enclosed accounts <br><html><table>'
SELECT @body = @body + '<tr><td>' + ISNULL(t.username, '') + ' ' + ISNULL(t.name, '') + '</td></tr>'
FROM table AS t
very quick and dirty but may get the job done. I have limited experience using XML method that is why I showed it using some basic HTML.
January 4, 2019 at 1:44 am
fixed it I just had too many columns in the CURSOR I removed them like so and it works now.
CURSOR FOR
select distinct reportsto,[Reports To Email] from #test
FETCH NEXT FROM VAR_CURSOR
INTO @reportsto, @VAR_ADDRESS;
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply