SQL Server 2005 SSIS SQL Execut SQL task to put single value in variable

I am trying to get a single column/row value into a variable. No matter what I try I do not get any values into my variable. Help.

SQL to get one column value:
select top 1 cast(ADMIN_EMAIL as varchar(100)) from ADMIN_EMAIL
(ADMIN_EMAIL = nvarchar(100), not null)
Result set user::MailTo (String)
Result Name = 0, Variable Name: user::MailTo
Connection Type: OLE DB
SQLSource: Direct Input
ResultSet: Single Row

 
Ima SelcoAsked:
Who is Participating?
 
nmcdermaidConnect With a Mentor Commented:
How are you verifying that your variable is not populated? Variable values are reset once run time os over. You can't run the package, stop it, then check the variable value as it will be reset.
Try adding a script task afterwards to display your variable (attached is one I quickly took out of one of my packages)
 

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
 
Public Class ScriptMain
 
 
Public Sub Main()
        Dim sVariable As String
        Dim vars As Variables
 
        Dts.VariableDispenser.LockOneForRead("DateFromSQLTask", vars)
        sVariable = vars(0).Value.ToString
        vars.Unlock()
 
        MsgBox(sVariable)
 
        Dts.TaskResult = Dts.Results.Success
 
        Dts.TaskResult = Dts.Results.Success
End Sub
 
End Class

Open in new window

0
 
Ima SelcoAuthor Commented:
I consider it a bug in MS Dev Studio when you execute a task, in debug mode, that updates a variable and the variable is unchanged after the task has executed.
0
 
nmcdermaidCommented:
Call it a feature :)
It doesn't really work that way though.... when you are in in design/debug mode, the variable is changed after the task is executed. Its only when you drop out of design mode that it changes.
Thats the nature of a variable.... its only there during run time. Thats the way most other development paltforms work. (except DTS of course!)
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.