Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:05:41+00:00 2026-05-24T01:05:41+00:00

I have what should be a simple task – Populate a user variable using

  • 0

I have what should be a simple task – Populate a user variable using the ResultSet from an Execute SQL task

SELECT MainID FROM TableA WHERE TableA_ID = 1` 

(This will only return one Column and one Row).

MainID is currently stored as a user-defined datatype in the database. The value is stored in the format XXXX.Y (e.g. 8008.1).

If I change the UserVariable to a String datatype, I can assign the value without any problems either CASTing or CONVERTing the ResultSet to STRING/NUMERIC/FLOAT.

SELECT CAST(MainID as NUMERIC(9,1)) as 'MainID' FROM TableA WHERE TableA_ID = 1;
SELECT CAST(MainID as FLOAT) as 'MainID' FROM TableA WHERE TableA_ID = 1;
SELECT CAST(MainID as VARCHAR(10)) as 'MainID' FROM TableA WHERE TableA_ID = 1;

or

SELECT CONVERT(NUMERIC(9,1), MainID) as 'MainID' FROM TableA WHERE TableA_ID = 1;
SELECT CONVERT(FLOAT, MainID) as 'MainID' FROM TableA WHERE TableA_ID = 1;
SELECT CONVERT(VARCHAR(10), MainID) as 'MainID' FROM TableA WHERE TableA_ID = 1;

However, I can’t assign the value if the User Variable Datatype is DOUBLE. I get the following error message:

[Execute SQL Task] Error: An error occurred while assigning a value to
variable “dUserVariable”: “The type of the value being assigned to
variable “User::dUserVariable” differs from the current variable type.
Variables may not change type during execution. Variable types are
strict, except for variables of type Object. “.

I’m fairly new to SSIS so I’m a bit stumped on how to get this conversion to go through.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:05:42+00:00Added an answer on May 24, 2026 at 1:05 am

    I am not sure if the following option will work in Web Service Task but you can give it a try.

    I think that the issue you have described is due to a limitation in SSIS while assigning numeric value to an SSIS package variable of data type Double. Refer this link to MSDN Connect where this issue has been reported.

    Here is a simple step-by-step example that illustrates an option that you can try. This example was created in SSIS 2008 R2.

    Create an SSIS package. I have named the package in the format YYYYMMDD_hhmm in the beginning followed by SO stands for Stack Overflow, followed by the SO question id, and finally a description. This is for me to easily refer this back later. Refer screenshot #1.

    On the package, create two variables namely StringValue and DoubleValue. Set the variable StringValue to numeric value (say 0). This is necessary so that the expression we are going to configure in the variable DoubleValue doesn’t error out. Select the variable DouleValue and press F4 to view the properties. Set the property EvaluateAsExpression to True and set the Expression property to (DT_DECIMAL, 2) @[User::StringValue] NOTE: At this point the Data Type on the variable DoubleValue will change to Cell is not a string. Refer screenshots #2 and #3.

    On the package, create an OLE DB connection manager to some SQL Server database. I have created a connection to Adventure Works database that I have on my local machine. Refer screenshot #4.

    On the Control Flow tab, place an Execute SQL Task and configure it as shown in screenshots #5 and #6. Double-click on the Execute SQL Task to bring the Execute SQL Task Editor. Set the ResultSet to SingleRow because we will be fetching only one value. Set the connection string to the OLE DB connection manager. The SQL Statement should be set to SELECT CAST('3.14' AS NUMERIC(10,2)) AS ValueOfPi. Result Set should be set to the variable StringValue.

    On the Control Flow tab, place a Script Task after the Execute SQL Task. This script task is just to show the value that will be assigned to the DoubleValue variable due to the expression that we just configured. Double-click on the Script Task to bring the Script Task Editor. Click on the Edit Script… button to bring the VSTA editor. Replace the Main() method with code given under Script task code section. Refer screenshots #7 and #8.

    Execute the package. The value in the variable DoubleValue should be displayed in a message box. Refer screenshot #9.

    Hope that helps.

    Script task code:

    C# code that can be used only in SSIS 2008 and above.

    public void Main()
    {
        Variables varCollection = null;
        Dts.VariableDispenser.LockForWrite("User::DoubleValue");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        MessageBox.Show(varCollection["User::DoubleValue"].Value.ToString());
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    

    Screenshots:

    #1:

    1

    #2:

    2

    #3:

    3

    #4:

    4

    #5:

    5

    #6:

    6

    #7:

    7

    #8:

    8

    #9:

    9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Using SQL Server 2000] I can't believe a simple task is being this complex
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
Should be pretty simple: I have an InputStream where I want to peek at
This should be a very simple task, but for some reason I'm running into
This seems like it should be a simple task, but I'm a noob as
I have the following issue whith this very simple task. I want to create
We should have a full release of asp.net MVC well before .NET 4.0 and
We have 18 databases that should have identical schemas, but don't. In certain scenarios,
When I asked this previously I should have mentioned that it's particularly a light-weight
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.