[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2009-02-23
Medium Priority
Last Modified: 2013-11-10
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

Question by:Ima Selco
  • 2
LVL 30

Accepted Solution

nmcdermaid earned 200 total points
ID: 23716865
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
        Dts.TaskResult = Dts.Results.Success
        Dts.TaskResult = Dts.Results.Success
End Sub
End Class

Open in new window


Author Closing Comment

by:Ima Selco
ID: 31550330
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.
LVL 30

Expert Comment

ID: 23728016
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!)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question