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 |
|
wbhall13
Starting Member
4 Posts |
Posted - 2004-06-16 : 21:32:59
|
| Help !!! I need to output my email addresses into a string output for group emailing. I am running the folowing SQL in SQL server to retive email addresses from a table:declare @email varchar(100)declare xemail cursor forSELECT [Pager] FROM [CNOC].[dbo].[SLGContacts_Email] where [Service Group]like 'White Plains%' and [Work Center ID]='416wp500' and [Category]='ACT' and [Y1]='1'open xemailwhile(0=0) beginfetch nextfrom xemailinto @emailif (@@Fetch_status <>0) BreakPrint @email +';'Endclose xemaildeallocate xemailThe output looks like this:gmancini@xtt.com;hobrown@xtt.com;nixonj@xtt.com;pertelesi@xtt.com;karlenesmith@xtt.com;spanaro@xtt.com;It needs to look like this:gmancini@xtt.com;hobrown@xtt.com;nixonj@xtt.com;pertelesi@xtt.com;karlenesmith@xtt.com;spanaro@xtt.comThis output will allow me to mail to a group of users based on a database query.... I am not sure if the correct output function is the "Print @email +','" if I need to use the output in my ASPmail tool (Mailer.AddAddress = the above SQL). Any suggestions??????Thanks in advance for your help....Bill |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2004-06-16 : 23:59:42
|
| Print will add a C/R.You're better off creating a new parameter to recieve the email string, so instead of:Print @email + ';' you would haveSET @emailList = @emailList + @email + ';'Then at the end you can either call Print @emailList or you can return the string as an output parameters (assuming it's a stored procedure...)Tim |
 |
|
|
wbhall13
Starting Member
4 Posts |
Posted - 2004-06-17 : 12:03:33
|
quote: Originally posted by timmy Print will add a C/R.You're better off creating a new parameter to recieve the email string, so instead of:Print @email + ';' you would haveSET @emailList = @emailList + @email + ';'Then at the end you can either call Print @emailList or you can return the string as an output parameters (assuming it's a stored procedure...)Tim
|
 |
|
|
wbhall13
Starting Member
4 Posts |
Posted - 2004-06-17 : 12:23:26
|
All, Thanks for your help.... I used the following solution to resolve the string issue:declare @emailList varchar(100)declare @email varchar(300)declare xemail cursor forSELECT [Pager] FROM [CNOC].[dbo].[SLGContacts_Email] where [Service Group]like 'White Plains1%' and [Work Center ID]='416wp500' and [Y1]='1'set @email=''open xemailwhile(0=0) beginfetch nextfrom xemailinto @emailListif (@@Fetch_status <>0) BreakSET @email = @email + @emailList +'; 'ENDclose xemaildeallocate xemailSelect @email as Group_MailSET NOCOUNT OFFGOOutput:Group_Mail wsif@xxt.com; wsif@xxt.com; wsif@xxt.com; wsif@xxt.com; wsif@xxt.com; (1 row(s) affected) How do I place the above output into my ASPmail address field? Here's what I have so far: (everything works except the email address output) I recieve the following error after submitting my form.. "Invalid addresses"if Notification.email_alarm.Value = "1" thenDim Mailer, SQL, Connection, ErrorMessage, mylistSQL = "UPDATE B_Notification SET email_date = '" & Notification.email_date.Text & "' WHERE Records ='" & CCDLOOKUP("Records", "Records_Count","",DBCNOC) & "' And hrid = '" & Notification.hrid.Text & "'"Set Connection = New clsDBCNOCConnection.OpenConnection.Execute(SQL)ErrorMessage = CCProcessError(Connection)Connection.CloseSet Connection = NothingOn Error Goto 0mylist = "declare @emailList varchar(100) declare @email varchar(300) declare xemail cursor for SELECT Pager FROM SLGContacts_Email where [Service Group] like 'White Plains1' and [Work Center ID]='416wp500' and [Y1]='1'" &_ "set @email='' open xemail while(0=0) begin fetch next from xemail into @emailList if (@@Fetch_status <>0) Break SET @email = @email + @emailList +'; '" &_ "END close xemail deallocate xemail Select @email as mailid SET NOCOUNT OFF GO"Set Connection = New clsDBCNOCConnection.OpenConnection.Execute(mylist)'SET list = mylistErrorMessage = CCProcessError(Connection) Set Mailer = Server.CreateObject("Persits.MailSender") Mailer.From = CCDLookUp("email", "P_Master_Employee", "emp_hrid='9594227'", DBCNOC) Mailer.FromName = CCDLookUp("emp_first, emp_last", "P_Master_Employee", "emp_hrid='9594227'", DBCNOC) Mailer.AddAddress mylist Mailer.Host = "localhost" Mailer.IsHTML = True Mailer.Subject = "CNOC - KPI Alarm Notification" Mailer.Body = "CNOC - KPI Alarm Notification<br><br>" & "Service Level Group: " & Notification.ServiceLevel.Text & "<br>" & "Highest Alarm WorkCenter: " & Notification.Workcenter.Text & "<br>" &_ "Date: " & Notification.Date1.Text & "<br>" & "Start Time: " & Notification.StartTime.Text & "<br>" & "End Time: " & Notification.EndTime.Text & "<br>" &_ "Category: " & Notification.Category.Text & "<br>" & "Alarm Status: " & Notification.TOA.Text & "<br>" & "Alarm Level" & Notification.TOAL.Text & "<br>" &_ "Total Tickets: " & Notification.Total_Tkts.Text & "<br>" & "Red Tickets: " & Notification.Red_Total_Tkts.Text & " Yellow Tickets: " & Notification.Yellow_Total_Tkts.Text &_ " Green Tickets: " & Notification.Green_Total_Tkts.Text & "<br>" & " No. of people on Tickets: " & Notification.NPOT.Text & "<br>" & "Root Cause: " &_ Notification.RootCause.Text & "<br>" & "Analysis: " & Notification.Analysis.Text & "<br>" & "Observations: " & Notification.Observations.Text Mailer.Send set Mailer = NothingConnection.CloseSet Connection = NothingOn Error Goto 0elseend ifThnaks,Bill |
 |
|
|
|
|
|
|
|