SSIS ForEach Variable Mapping Error - variables

I want to be able to send emails using SSIS. I followed the instructions at "How to send the records from a table in an e-mail body using SSIS package?". However, I am getting an error:
Error: ForEach Variable Mapping number 1 to variable "User::XY" cannot be applied
while running the package. My source table has 5 columns (bigint, datetime, nvarchar, nvarchar, nvarchar types).
Another error is:
Error: The type of the value being assigned to variable "User::XY" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
What could the problem be?
UPDATE: As I was trying to find out the problem, I have done this: while taking the data from Execute SQL Task, I cast the int data to varchar and then use the variable with String data type and it works. But how should I set the variable so it has INT data type, not varchar?

I just ran into this problem & resolved it, although I don't know exactly how.
Running SSIS for SQL Server 2008 R2:
a) query pulls rows into an object
b) for each trying to loop through and pull values for the first two columns into variables
(this had already been running fine--I had come back to edit the query and the for each loop and add an additional variable for branching logic)
c) error mapping variable '1', which happened to be an int and happened to have the same name as the column I was pulling from.
I tried deleting the variable-to-column reference in the foreach loop and re-adding it, and I discovered that the variable was not listed anymore in the list of variables allowed for mapping.
I deleted the variables, created a new variable of the same type (int32) and name, added it, and things ran fine.

Related

SSIS OLEDB Source output parameter datatype

I'm creating an SSIS package targeting SQL Server 2016. I'm trying to call a stored procedure in an OLE DB Source inside a Data Flow Task that has an output parameter I'm looking to set into a variable. I have the variable defined as a Int64 in SSIS and defined as a BIGINT in the procedure, but SSIS keeps returning the error:
Error: The type of the value (Decimal) being assigned to variable "User::SomeOutput" differs from the current variable type (Int64). Variables may not change type during execution. Variable types are strict, except for variables of type Object.
I have no idea why it's seeing a decimal. If I change my local SSIS variable to a decimal it doesn't error, but I want it to be a BIGINT/Int64
To recreate the issue you can create this stored procedure:
CREATE OR ALTER PROCEDURE [dbo].[Pr_GetTestProcedure] #SomeOutput BIGINT = NULL OUTPUT
AS
SET #SomeOutput = 8
SELECT 'Yes' AS Something
GO
Then create a local user variable:
Then create a data flow with an OLE DB Source calling the stored procedure:
Then set the parameters to the user variable defined as Int64:
Running the package will return the error I have listed above.
It appears to be a long running issue with SSIS supporting SQL Server's bigint datatype; apparently at the time of design/dev of SSIS, 64 bit integers were not yet standard across products. You can read the bigint value into a DECIMAL SSIS variable (or into an OBJECT whose type will become decimal).
There are many references to this problem, example: https://techcommunity.microsoft.com/t5/sql-server-integration-services/why-can-8217-t-i-store-my-bigint-result-in-an-int64-variable/ba-p/387335

ODBC source doesn't receive dynamic variable value

I am designing an incremental load for my ETL solution in SSIS. For that, I have an Execute SQL task that gets the maximum load time from the data warehouse and then stores it in a package variable, which is already set to evaluate as expression.
Then I have set the ODBC source's sql command property to an expression that has my query and the variable. However, I have looked into the variable during debug and when I run the package it seems that this variable doesn't get used in the sql command, instead it remains null.
I have already tried setting the variable property 'EvaluateAsExpression' to True, I have tried storing the query in a different variable and then setting that as the sql command for my ODBC source.

Refresh Expression after script task

Bumping due to no suggestions
I have an SSIS package with a declared variable - claimMaxDate. The first step in my package is to populate the variable with the MAX(TIME_STAMP) from a SQL Server table.
I want to use that date to run a different query but it must use the ODBC data source in SSIS.
Since parameters can't be passed to the ODBC data source, I'm trying to use expressions.
This is what I've added to the data flow task:
However, the expression never refreshes with the date that is populated in the variable. I've debugged and confirmed that the variable is being populated. Variable property EvaluateAsExpression is also true.
Am I missing a step here?
I would rather change your package design. Create a string variable like SQL_DFT_Select which evaluates with your expression. Then specify this variable as a query source at ODBC data source. By doing this you can set a breakpoint at your Data Flow Task step and check this variable.
On your original question -- it can be the case that your expression is evaluated at validation time, then your claimMaxTime variable is empty. Later change of this variable does not trigger update of property expression. However, every reading of a variable with an expression re-evaluates this expression; that is why I recommended switching to query from variable design.
Just in case anyone else come across this question. The answer was simple. The expression was evaluating at run time, it just doesn't show the update when debugging.

SSIS How to select user variable dynamically based on value of another user variable

I have a ForEach loop for importing all available tables in source connection. I am using following user variables for this:
OracleTables of type System.Object for holding all tables from oracle DB
TableName for enumerating OracleTables of type String
set of Boolean variables (e.g. Enable_TABLENAME) one for each table to hold whether that table is to be imported or not.
Now, I want to configure the DataFlow task inside ForEach loop to run iff the value of corresponsing table variable if true. Basically, I want something like:
!#[User::Enable_#[User::TableName]] for Disable property of DataFlow task.
that is, I want to get the Boolean table variable for for current table held by TableName variable.
How can I achive this? Or else, is there any better way to do this? Any pointers would be really helpful.
You can use ForEach Item Ennumerator (you can define your Items in the editor itself) or NodeList Ennumerator (and have your values in an XML file) or ADO.Net Ennumerator ( have your values coming from a SQL table instead).

SSIS - Date Coloumn to Variable Null and non-Null Values

Within an SSIS package I have a dataflow that extracts two coloumns from an access database a TaskID and a date
I store this in a ADO recordset and pass this to a For Each Loop Container
I am them attempting to assign each value pair to two variables "taskID" and "taskDate"
I then want to use thse two variables within a SQL Insert task that will then update the SQL database in several places with this information
The package works fine when im just pull out the taskID and insert that into sql but when i introduce the date it fails because the date can be NULL and most of the tasks are NULL but SSIS just keeps telling me that it cant put null into the variable, I tried having an Obejct variable which allowed nulls but then the package fails on adding the variable to the sql task as the variable in there is a DATE?
Thanks
There's a possible solution outlined here that uses a second variable and EvaluateAsExpression that may solve your problem.