I'm fairly new to this type of thing I need to query a table and use the results to populate a CC list for an email message. I can't find anything that shows an example of this specifically. I'm using a Job in SQL server to accomplish this task. Sending to one recipient and one CC recipient works great but I need to send multiple CCs. Any advice would eb greatly appreciated.
Here's my code that sends an email to one recipient:
declare @chvFirstName nvarchar(100),
@chvLastName nvarchar(100),
@chvEArea nvarchar(5),
@chvAppDate nvarchar(20),
@chvExpDate nvarchar(20),
@chvEmail varchar(50),
@chvEmailMessage varchar(800)
declare @CrsrVar Cursor
Set @CrsrVar = Cursor For
Select App.dbo.CommitteeAPC.AppointDate, App.dbo.CommitteeAPC.ExpiryDate, App.dbo.CommitteeAPC.ElectoralArea, App.dbo.CommitteeMemberContact.FirstName, App.dbo.CommitteeMemberContact.LastName, App.dbo.CommitteeAPC.StaffEmail
From RDOS_App.dbo.CommitteeAPC INNER JOIN App.dbo.CommitteeMemberContact ON App.dbo.CommitteeAPC.MemberID = App.dbo.CommitteeMemberContact.MemberID
Where CurrentDate > NotifDt
Open @CrsrVar
Fetch Next From @CrsrVar
Into @chvAppDate, @chvExpDate, @chvEArea, @chvFirstName, @chvLastName, @chvEmail
While(@@FETCH_STATUS = 0)
Begin
set @chvEmailMessage = 'DO NOT REPLY TO THIS MESSAGE! This is an automatic e-mail notification ' +
'message sent to you from the Committees Database.' +
CHAR(13) + CHAR(10)+
CHAR(13) + CHAR(10)+
'The following APC membership will expire in approximately 30 days.' +
CHAR(13) + CHAR(10)+
CHAR(13) + CHAR(10)+
'Name: ' + @chvFirstName + ' ' + @chvLastName +
CHAR(13) + CHAR(10)+
CHAR(13) + CHAR(10)+
'Area: ' + @chvEArea + ' Advisory Planning Commission' +
CHAR(13) + CHAR(10)+
'Date Appointed: ' + @chvAppDate +
CHAR(13) + CHAR(10)+
'Date of Expiry: ' + @chvExpDate
--Use Master
Exec msdb.dbo.sp_send_dbmail
@profile_name = 'App Database Mail Profile',
@recipients = @chvEmail,
@subject = 'An APC Membership will expire within 30 days',
@body = @chvEmailMessage
Fetch Next From @CrsrVar
Into @chvAppDate, @chvExpDate, @chvEArea, @chvFirstName, @chvLastName, @chvEmail
End
Close @CrsrVar
Deallocate @CrsrVar
varcharvalue with;as a delimiter. what does@chvEmailcontains? All you need to do is parse it to the correct format.