Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-09 : 09:27:21
|
| Deepika writes "I have a number of tasks in my DTS package ( e.g: transform data task, bulk insert, Execute SQL etc).. On failure of any of these tasks, i need to send an email notification to the concerned users that a particular task has failed.. The number of users keep changing day-by-day i.e.new users( recipients of the SQL mail notification) are added everyday.. Currently, each time a new user gets added, i have to change the SQL mail task( which uses the stored procedure xp_sendmail).Question:How is it possible to add users without having to change the '@recipients' argument of xp_sendmail stored procedure, each time.SQL Server version: SQL Server 2000OS: Windows NT" |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-04-09 : 10:02:32
|
| Send the email to a distribution list which you can modify to your hearts content on your exchange server.setBasedIsTheTruepath<O> |
 |
|
|
Günnie
Starting Member
4 Posts |
Posted - 2002-04-09 : 10:18:14
|
| Hi,I know it is not the best solution, but the most simple way is using a cursor scrolling through a Table which contains the recipients.1st Create the Table:CREATE TABLE MailRecips ( recip varchar(40) NOT NULL, topic varchar(40) NOT NULL )recip is 1 recipient of a mail, topic is the key (or maybe the subject of the mail)Entries in this table look like this...recip - topic-----------------------john - Blablaronda - Blablatom - Another Topic-----------------------2nd scroll through your new table to fetch all recipients for xp_sendmail:DECLARE @topic varchar(40)SELECT @topic='Topic which should be sended'DECLARE @recipOne varcharDECLARE @recipAll varchar(1000)--We declare and open the cursor for a specific mailDECLARE crs CURSOR FORSELECT recip FROM MAILRecips WHERE topic = @topicOPEN crsFETCH NEXT FROM crs INTO @recipOne----Scrolling through the tableSELECT @recipAll = ''DO WHILE @@FETCH_STATUS = 0BEGIN SELECT @recipAll = @recipAll + ';' + @recipOne FETCH NEXT FROM crs INTO @recipOneEND@recipAll=Right(@recipAll,Len(@recipAll)-1)----Closing the cursorCLOSE crsDEALLOCATE crs----Sending mailEXEC xp_sendmail @recpients=@recipientAll, ... |
 |
|
|
|
|
|
|
|