SSIS Expression Exception - ssis

I have the following SSIS expression, which is giving me an error but I am unable to resolve it. Any help would be appreciated.
Objective: Include new condition, if BatchManagement != X, set value as 0.
Original Query
(DT_WSTR,20)(REPLACENULL(WMSBatchNo,0))
Modified Query
(DT_WSTR,20)(REPLACENULL(BatchManagement,"") != "X" ? 0 : REPLACENULL(WMSBatchNo,0))
Error Message:
Error at Step 1 - Fetch CRM Data and Write to File [Convert Data
[34]]: The data types "DT_I4" and "DT_WSTR" are incompatible for the
conditional operator. The operand types cannot be implicitly cast into
compatible types for the conditional operation. To perform this
operation, one or both operands need to be explicitly cast with a cast
operator.
Error at Step 1 - Fetch CRM Data and Write to File [Convert Data
[34]]: Attempt to set the result type of conditional operation
"REPLACENULL(BatchManagement,"") != "X" ? 0 :
REPLACENULL(WMSBatchNo,0)" failed with error code 0xC004709F.
Error at Step 1 - Fetch CRM Data and Write to File [Convert Data
[34]]: Computing the expression
"(DT_WSTR,20)(REPLACENULL(BatchManagement,"") != "X" ? 0 :
REPLACENULL(WMSBatchNo,0))" failed with error code 0xC00470A0. The
expression may have errors, such as divide by zero, that cannot be
detected at parse time, or there may be an out-of-memory error.
Error at Step 1 - Fetch CRM Data and Write to File [Convert Data
[34]]: The expression "(DT_WSTR,20)(REPLACENULL(BatchManagement,"") !=
"X" ? 0 : REPLACENULL(WMSBatchNo,0))" on "Convert
Data.Outputs.Columns[WMSBatchNumber]" is not valid.
Error at Step 1 - Fetch CRM Data and Write to File [Convert Data
[34]]: Failed to set property "Expression" on "Convert
Data.Outputs.Columns[WMSBatchNumber]".

Related

SSIS derived column error (cast type)

I am trying to sum 2 columns (adjustment due day and expiration day):
DATEADD("dd",(DT_I4)AdjustmentDueDayCode,ExpirationDate)
I keep getting the following error message:
An error occurred while attempting to perform a type cast
SSIS Error Code `DTS_E_INDUCEDTRANSFORMFAILUREONERROR*`
I thought it could be because of nulls so wrote the following:
(DT_I4)AdjustmentDueDayCode > 0 ? (DATEADD("dd",
(DT_I4)AdjustmentDueDayCode,ExpirationDate) : "null"
But still getting the same error, any recommendations?
AdjustmentDueDaycode needs to become type BIGINT.
IE)
DATEADD("dd", CONVERT(BIGINT, (DT_I4)AdjustmentDueDaycode),ExpirationDate)

SSIS Import a date and time from a txt to a table datetime

So I want to import a datetime from a txt:
2015-01-22 09:19:59
into a table using a data flow. I have my Flat Source File and my destination DB set up fine. I changed the data type for the txt input for that column in the advanced settings and the input and output properties to:
database timestamp [DT_DBTIMESTAMP]
This is the same data type as the DB used for the table so this should work.
However, when I execute the package I get a error saying the data conversion failed... How do I make this possible?
[Import txt data [1743]] Error: Data conversion failed. The data conversion for column "statdate" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
[Import txt data [1743]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "statdate" (2098)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "statdate" (2098)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
[Import txt data [1743]] Error: An error occurred while processing file "C:\Program Files\Microsoft SQL Server\MON_Datamart\Sourcefiles\tbl_L30T1.txt" on data row 14939.
On the row he is giving the error the datetime is filled up with spaces. that is why on the table the "allow nulls" is checked but my SSIS package gives the error for some reason... can I somewhere tell the package to allow nulls aswell?
I suggest you import the data in to a character field and then parse it after entry.
The following function should help you:
SELECT IsDate('2015-01-22 09:19:59')
, IsDate(Current_Timestamp)
, IsDate(' ')
, IsDate('')
The IsDate() function returns a 1 when it thinks the value is a date and a 0 when it is not.
This would allow you to do something like:
SELECT value_as_string
, CASE WHEN IsDate(value_as_string) = 1 THEN
Cast(date_as_string As datetime)
ELSE
NULL
END As value_as_datetime
FROM ...
I solved it Myself. Thank you for your suggestion gvee but the way I did it is way easier.
In the Flat File Source when making a new connection in the advanced tab I fixed all the data types according to the table in the database EXCEPT the column with the timestamp (in my case it was called "statdate")! I changed this data type to a STRING because otherwise my Flat File Source would give me a conversion error even before any scripts would have been able to be executed and the only way arround this was setting the error output to ignore failure wich I don't want. (You still have to change the data type after you set it to a string in the advanced settings by right clicking the flat file source -> show advanced editor -> going to the output colums and changing the data type there from Date to string.)
After the timestamp was set to a string I added a Derived Column with this expression to delete all the spaces and give it then "NULL" value:
TRIM(<YourColumnName>) == "" ? (DT_STR,4,1252)NULL(DT_STR,4,1252) : <YourColumnName>
Next I added a Data Conversion to set the string back to a timestamp. The Data conversion is finally connected to the OLE DB Destination.
I hope this helps anyone with the same problem in the future.
End result: Picture of data flow

SSIS - Use Derived Column to Cast String to Float

I'm having a problem getting data from a .CSV into a column of datatype FLOAT. I've tried to link it directly and also use the Data Conversion Task, but (in both cases) it kept telling me that it couldn't convert:
Error: 0xC02020C5 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Data Conversion [156]: Data conversion failed while converting column "Target" (22) to column "Copy of Target" (163). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
My research led me to using the Derived Column Transformation Editor. I found a few websites that walked me through how properly use the "Expression" portion:
Above is how I'm attempting to transform the strings (Target and Waste) into datatype Float. I'm not receiving an error message when using the Editor (i.e. It will let me clik OK without an error), however, I am receiving an error when I attempt to run the package:
Error: 0xC0049064 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Map Target in correct datatype 1 1 [222]: An error occurred while attempting to perform a type cast.
Error: 0xC0209029 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Map Target in correct datatype 1 1 [222]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "component "Map Target in correct datatype 1 1" (222)" failed because error code 0xC0049064 occurred, and the error row disposition on "output column "Target_Float" (227)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
Error: 0xC0047022 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Map Target in correct datatype 1 1" (222) failed with error code 0xC0209029 while processing input "Derived Column Input" (223). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
This is my first time using the Derived Column Transformation Editor. Does anyone see what I'm doing incorrectly? Or, do you have any suggestions as to what may be the best approach to getting data from a .csv file into a column of datatype float? I appreciate any help that anyone can give me.
You have tried a reasonable approach but something in the data is blowing it up - possibly "invalid" characters e.g. $ or ,
I would replace the Derived Column transformation with a Script Task. There you can leverage the .NET Framework e.g. Try ... Catch, TryParse, Regex. You can debug your code line-by-line to inspect the rows with errors. You can also use Reflection to factor your conversion code as a function that you call for each column passed into the Script Task.
PS: your destination is irrelevant.

SSIS The expression for variable 'Variable' failed evaluation. There was an error in the expression

So here we have an error I keep getting in my SSIS package but I can't see what is wrong with the statement. I have even tried another sql statement from a project that works and it still raises the error.
The system is VS 2005 running 64 bit debugger, on XP machine. The project has amongst other things a script task then a sql task, the script task outputs the month value to a variable (Dts.Variables("monthName").Value = month), which I then use to create dynamic table name in SQL statement. I haven't got to the excel sheet bit yet as I am trying to get the sql task stage working.
So i have a variable at package level called SQLTableCreate, and in that I have the properties set to:
Evaluate as Expression = true
Expression = "Create Table "+ #[user::monthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
And when I build the package I get:
Nonfatal errors occurred while saving the package:
Error at Package: The variable "user::monthName" was not found in the Variables collection. The variable might not exist in the correct scope.
Error at Package: Attempt to parse the expression ""Create Table "+ #[user::MonthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
" failed and returned error code 0xC00470A6. The expression cannot be parsed. It might contain invalid elements or it might not be well-formed. There may also be an out-of-memory error.Error at Package: The expression for variable "SQLTableCreate" failed evaluation. There was an error in the expression.
There is also a default SQL statement for the variable SQLTableCreate, which uses the current excel connection manager table name. When I put my dynamic statement in the expression section of properties it fills the value and valuetype property of the SQLTableCreate variable with the message:
The expression for variable "SQLTableCreate" failed evaluation. There was an error in the expression.
It's exactly as the error says
The variable "user::monthName" was not found in the Variables collection
Things in SSIS are case sensitive and Variables are one of those things. Make your expression
"Create Table "+ #[User::monthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
Also, I hope this table design is just a sample and not real. Lack of column names and strong data types is technical debt you don't need to incur at this stage.

Assigning single resultset to multiple variables in ssis

I have an execute sql task , where i have used an sql query to get the data, now the result of this data has to be passed to three varibales.
So in Execute SQL TASK, i have done mapping in the following way
ResultType ------ FullResultSet
ParamterMapping --- id
ResultSet
0 path
1 file
2 Type
Variables path, file and type are of string type.
when i run the package EST is throwing the following error.
[Execute SQL Task] Error: There is an invalid number of result bindings returned for the ResultSetType: "ResultSetType_Rowset".
Are you trying to save multiple rows in your variable? If you do, don't set the result set to 'single row'. If not, your variable types have to be of type object.
Maybe have a look at this as reference, too.
http://www.networksteve.com/enterprise/topic.php?TopicId=44489
Having
rsFromSql
var1,var2,var3
The quickest and simplest way is
sql task
rsFromSql <- select x,y,z from mytable
and adding a
foreachloop task with recordset ado after the executesql
mapping the vars
if you return just 1 row from the sql task
set result to singlerow in sql task
and map the column as vars in order
0 x
1 y
2 z
cheers