In my SSIS 2005 package, in OLE DB source (SQL Server 2005), I tried to execute a query with one parameter
The query in the OLE DB source
select
...
from..
where
txn_date_time >= ?
As you can see, the query takes one parameter from variable. The variable is type string and value is 20140622
Got this error in the OLE DB source when run the package.
...
Description: "Invalid character value for cast specification".
Also tried this and got the same error.
txn_date_time >= cast(? as datetime)
The query can be run perfectly in SSMS, e.g.
select
...
from..
where
txn_date_time >= '20140622'
It seems to me that SSIS only allow parameter of type date time to be passed to the query because txn_date_time is type date time. Do I have to change the variable to type Date time?
Check the data type of the value returned by your query and the data type of the parameter that you are mapping it to. They should be compatible else you get such cast exceptions.
Related
Hi I am trying to return a ResultSet from an "Execute SQL Task" in SSIS.
I am then trying to save the result in a "ResultSet" variable.
My Query works in the console and my connection is ok to.
Here is my Query
SELECT Src FROM [myDB].[dbo].[myTable] group by Src
Src is nvarchar(255)
When I execute the task I am getting following error
[Execute SQL Task] Error: Executing the query "SELECT Src
FROM [myDB].[dbo].[myTable..." failed with the following error: "The type of the value (DBNull) being assigned to variable "User::ResultSet" differs from the current variable type (String). Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I am also attaching the screen shots for the Task setup.
Please help.
ExecuteSQL Screen1
ExecuteSQL Screen2 - ResultSet setup
In SSIS 2012 within a ForEach loop using an ADO enumerator, you are unable to assign a null value to a variable of type String when the source value came from a SQL query returning a null value.
I would suggest Derived Column Transform feature of SSIS
you'll use the SSIS ISNULL function to detect the NULL value - and then do something with it.
More info about Derived Column Transform
For example transforming String column:
ISNULL([String-Column]) ? "There Was No Value" : [String-Column]
I am working in SQL Server 2008 and BIDS (SSIS). I am trying to generate a "load ID" for when a package is executed and store that ID in a load history table (which then populates subsequent tables).
My basic SSIS control flow is the following:
Execute SQL Task, Data Flow Task
The load table is created via the following:
CREATE TABLE dbo.LoadHistory
(
LoadHistoryId int identity(1,1) NOT NULL PRIMARY KEY,
LoadDate datetime NOT NULL
);
The editor for the Execute SQL Task is as follows:
General:
ResultSet = None
ConnectionType = OLE DB
SQLStatement:
INSERT INTO dbo.LoadHistory (LoadDate) VALUES(#[System::StartTime]);
SELECT ? = SCOPE_IDENTITY()
Parameter Mapping:
Variable Name = User::LoadID
Direction = Output
Data Type = LONG
Parameter Name = 0
Parameter Size = -1
SSIS is throwing the following error:
[Execute SQL Task] Error: Executing the query "INSERT INTO dbo.LoadHistory
..." failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
This error message doesn't really help me find the problem. My best guess is that it's due to the parameter mapping, but I don't see my mistake. Can anybody point out my problem and provide the fix?
I figured out my problem. System::StartTime needs to have DATE as its data type, not DBTIMESTAMP.
I was passing three parameters.
In the Parameter Name property I had:
0
1
3
Corrected it to:
0
1
2
It works now, no multiple-step operation generated errors message.
I am trying to retrieve the value of Key from a table with a simple select statement in SSIS through Execute SQL Task. But have no luck figuring out this error.
I have used one input variable with string data type and used this variable in parameter mapping in Execute SQL Task.
Executing the query "SELECT cast([Key] as Int) FROM Table where
column = ?" failed with the following error: "An error occurred while
extracting the result into a variable of type (DBTYPE_I4)". Possible
failure reasons: Problems with the query, "ResultSet" property not set
correctly, parameters not set correctly, or connection not established
correctly.
Note : Datatype for Key column is tinyint
This message occurs when the default datatype for the parameters remains as 'LONG' instead of whatever is necessary... In your case, this should be 'BYTE'
Tinyint is not i4, it's DT_UI1. http://msdn.microsoft.com/en-us/library/ms345165.aspx
If you change your SSIS type to byte then you should be able to assign the results of your query to the value.
Variable User::input Data Type Byte Value 2
Variable User::output Data Type Byte Value 0
Source query SELECT CAST(1 AS tinyint) AS [key], ? AS foo
Execute SQL Task, OLE DB CM, single row result set
Parameter mapping tab
Variable Name: User::input
Data Type: Byte
Parameter name: 0
Result of column 1 mapped to User::output
Inspect value after Execute SQL Task and result is 2 (expected)
Write the query like -> SELECT cast([Key] as Int) as Key FROM Table where column = ?
The Error from the execute sql task is
The type of the value being assigned to variable "User::ReturnResult" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
The SSIS package was working fine till date but suddenly it showed an error today .
The script which i wrote in execute sql task is
Declare #ReturnValue int
EXEC #ReturnValue = DATABASE.dbo.StoredProcedure
Select #ReturnValue
The result set is configured to single row and in the resultset
ResultName= 0
VariableName=User::ReturnResult
The return value from the stored proc is either 0 or -1 ( Success or failure )
Since it is a production issue i dont have access to SP or the tables . So can this error occur due to connection issue with the Sybase server or its an issue with the Stored proc
Your error message is telling you that the stored proc is no longer returning just the 0 or -1 you are expecting (could it be returning null?)
Use a tool like sql server profiler to verify the parameters being passed into the stored proc and emulate the same steps to understand why the return type is different.
I'm trying to use an Execute SQL Task in SSIS 2008 to map a store procedure output parameter to a package variable.
The package variable is SSIS type DateTime and the store procedure parameter is SQL type DATETIME.
The SQL Statement is EXEC GetCurrentDate #CurrentDate=? and in the parameter mapping screen, the parameter is mapped to the package variable with direction Output and Data Type DBTIMESTAMP specified.
When I run the package I get the following error:
[Execute SQL Task] Error: Executing
the query "EXEC GetCurrentDate
#CurrentDate=? " failed with the
following error: "The type of the
value being assigned to variable
"User::CurrentDate" differs from the
current variable type. Variables may
not change type during execution.
Variable types are strict, except for
variables of type Object. ". Possible
failure reasons: Problems with the
query, "ResultSet" property not set
correctly, parameters not set
correctly, or connection not
established correctly.
If I run a trace on the query being run I see the type is being assumed as datetime2:
declare #p3 datetime2(7)
set #p3=NULL
exec sp_executesql N'EXEC GetCurrentDate #CurrentDate=#P1 ',N'#P1 datetime2(7) OUTPUT',#p3 output
select #p3
Does anyone know why it is assuming the type is datetime2?
Thanks
Found the answer on a Micorsoft Connect bug report:
We are closing this case as this is expected behaviour and is a result of the new sql datetime type change. You are using a native oledb connection manager for sql task, in the process of COM interop, we use VARIANT to hold the value and the only way to prevent data loss is to store the value as BSTR variant. If you change User::dateParam to String type it will work, or you can switch to use managed connection manager to bypass the COM interop.
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=307835
Try specifying the inout/output parameters as DATE rather than DBTIMESTAMP in the SSIS task.
This certainly works in SSIS 2005 packages I've worked on.
It's also worth taking a look at this link, which covers this as well as a couple of other issues with SSIS and dates.