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.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 SQL Task Resultset to email

Author  Topic 

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2007-09-20 : 10:04:57
Hello,

I have data (using Full Result Set) and would like to email values.

Query output from SQL Task:
ID Client
1 ABC
2 Acme
3 Holtz

Goal email output (inside Script Task):

The following records found today:
ID Client
1 ABC
2 Acme
3 Holtz


Thank you in advance.

Note: I know how the email works, it's just passing the resultset I need help on.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-09-20 : 10:19:45
you can use Database Mail for this. it's explained in BOL.

EDIT: DB Mail works for normal queries against the relational engine. not sure about the SSIS aspect of it though. (I didn't realize at first this post was in the SSIS forum!)


elsasoft.org
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2007-09-20 : 10:24:42
Thanks, jezemine. But for the sake of learning using other solution you think this can be accomplished using Script Task reading as Dataset and use StringBuilder then pass concatenated value in the email?
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2007-09-21 : 09:12:40
Hope this useful to someone...


Email output
List of stuff due today 9/21/2007 :
ID : 100
ID : 101
etc...

Execute SQL Task
' General > Resultset = Full Result set
' Result Set > Result Name = 0, Variable Name = User::ObjectName

Script Task
' ReadWriteVariables = ObjectName

Imports System
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Net.Mail
Imports System.Net
Imports System.Data
Imports System.IO
Imports Microsoft.SqlServer.Dts.Pipeline
Imports System.Text

Public Class ScriptMain
Public Sub Main()
Dim msg As MailMessage
Dim smtp As SmtpClient

Dim dt As Data.DataTable
Dim ad As New Data.OleDb.OleDbDataAdapter
dt = New System.Data.DataTable
ad.Fill(dt, Dts.Variables("User::ObjectName").Value)

Dim data As String

' Iterate rows and concatenate into data variable
For Each row As Data.DataRow In dt.Rows
For Each column As Data.DataColumn In dt.Columns
data = data & (column.ColumnName & " : " & row(column.Ordinal).ToString()) & "<br>"
Next
Next

Dim sendNotify As String
sendNotify = "<pre>List of stuff due today " & Today() & " : <br><br>" & data.ToString() & ""

msg = New MailMessage( _
"fromyouremail@mail.com", _
"toyouremail@mail.com", _
"Subject: Here's My Stuff", sendNotify)
smtp = New SmtpClient("myServer")
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
msg.IsBodyHtml = True
smtp.Send(msg)
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
Go to Top of Page
   

- Advertisement -