SSIS OLEDB Source output parameter datatype - sql

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

Related

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.

The SQL command requires a parameter named "#SessionID", which is not found in the parameter mapping

I'm trying to execute a stored procedure via SSIS
Error: 0xC0207014 at PO Header, OLE DB Source [59]: The SQL command
requires a parameter named "#SessionID", which is not found in the
parameter mapping.
But as you can see below, the variables are populated, I have mapped the parameters.
So what's going on?
MS SQL 2014
MS Visual Studio 2015
Based on the screenshots, you have mapped variables to parameters. Then just try to delete and recreate the OLE DB Source.
The SQL command requires a parameter, which is not found in the parameter mapping
If it still throwing an error, then use expressions instead of parameters. You can refer to the following link for more information:
Unable to pass a variable value to a stored procedure in ssis
I was having the same issue and even having Visual Studio crash on me. I found that rather than using parameter index of 0,1, 2... I used named parameters in my OLEDB connect and this resolved my error. You must include the # in the parameter name and they must match your sql stored procedure parameter names.
For example instead of [0] and [1] name parameters #StartDate and #EndDate

How to invoke stored procs with parameter using T-SQL scripting?

We are using edge-sql to execute T-SQL scripts and also stored procedures via C#. I noticed recently that stored proc support has been added and I'm trying to execute would would be:
exec dbo.sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx';
in SQL Server Management Studio, using edge-sql 0.1.2.
I've played around with several variations, but I get one of 2 error messages. Either cannot find stored procedure '' or "cannot find stored procedure 'sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx'" The stored proc executes just fine in edge.sql when invoked via C# method.
I did some additional experimentation and found I can execute a stored proc with no parameters: exec dbo.sgVersionGet, but any stored procs with parameters return errors.
So what am I doing wrong? And how could I invoke with parameter values that aren't hard-coded, as above? Both SQL Server and edge use the # character for parsing params.
Any help appreciated ...
-BillyB
In SQL Server when you are referring to a database object without the object full path ([database.schema].object), SQL Server will try to locate the object using the Default/Initial Catalog value which points to the default database if that was not specified within the connection string then chances are that when you try running your statement SQL Server won't be able to find the object throwing the "Cannot find XX" error, You should either specify an initial catalog on your connection string or execute your procedures using the full path, database.schema.procedure E.g. mydatabase.dbo.sp_customerCleanUp. On the other hand there is an internal procedure sp_executesql that you can use to run your procedures without having to hard code the parameters, all you need to do is build a string concatenating the hard coded part of the string (the procedure name) and whatever number of variables you are passing as parameters, see example ( https://technet.microsoft.com/en-us/library/ms175170%28v=sql.105%29.aspx )
The variables are assumed when calling a stored procedure with edge-sql. Any parameter you would preface with an '#' symbol will need to have the same name within the stored procedure.

Conditionally changing a variable data type based on input

We have a stored procedure that gets call from an application. One of the input to the SP is SSN. We are using SQL Server 2008R2 Enterprise Edition.
The SSN data type is input as VARCHAR(9). We take that SSN and join it to a table who has the SSN stored as DECIMAL(9,0). This causes an implicit conversion at execution time and is affecting performance.
My original plan was to have the input come in as VARCHAR and just copy the variable over to another variable with the DECIMAL datatype however, we have a kink in the process. A user can also input text as 'new' when there is a new client. When this happens, we get a failed to convert datatype varchar to decimal.
Is there a way to conditionally change the data type of a variable based on the input it receives?
Here's an example of what I am trying to use now, to no avail, as the instances where 'new' is entered cause a conversion error:
CREATE PROCEDURE [dbo].[StoredProcedureFromApplication](
#SubscriberSSN VARCHAR(9))
AS
DECLARE #SSN_DEC DECIMAL(9,0)
SET #SSN_DEC = #SubscriberSSN
Any ideas on how to have the datatype able to be changed?
First, you should store SSNs as strings and not numbers, because they can start with 0.
I think the best you can do is to have the resulting value be NULL
SET #SSN_DEC = (case when isnumeric(#SubscriberSSN) = 1
then cast(#SubscriberSSN as decimal(9, 0))
end);

SSIS ForEach Variable Mapping Error

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.