I'm getting the following error on an SSIS package:
[Execute SQL Task] Error: Executing the query "EXEC [spGetFileId] @zFileName, @Id" failed with the following error: "The type of the value being assigned to variable "User::FileId" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
I have created an Execute SQL Task which executes a simple stored procedure on the SQL server:
CREATE PROCEDURE [dbo].[spGetFileId]
@zFileName VARCHAR(255),
@Id INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT @Id = [Id]
FROM [tblFileLog]
WHERE [zFileName] = @zFileName
END
The SQLStatement property of the task is:
EXEC [spGetFileId] @zFileName, @Id
I have the following SSIS variables:
- User::File (String)
- User::FileId (Int)
and the parameters are mapped on the SQL task as follows:
- Variable | Direction | Type | Parameter
- User::File | Input | String | @zFileName
- User::FileId | Output | Int32 | @Id
I've tried playing around with the variable types (int16
, int32
and int64
; even string) but the error persists. Please help!
EDIT:
Debugging the stored procedure I added a PRINT @Id
before the END
and this outputs the expected value but when doing SELECT @Id
(the output param) this returns NULL
.
EDIT2:
A coworker has identified the problem and offered his solution which I have marked as answer below.