SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


For Each loop not enumerating recordset correctly


For Each loop not enumerating recordset correctly

Author
Message
aaron.reese
aaron.reese
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2415 Visits: 907
Guys,

I am importing data from a flatfile source which has a header record, some data rows and a trailer record in the format

Total Records: NNNNNNN

Where NNNNNN is a numeric value with leading zeros to pad it out to 7 digits (e.g. 0000005)

I need to get this mumeric value into the database so this is what I have done.

Set up a flatfile source to the file with a single column (WT_STR)
Conditional Split on the first 5 characters (to find the word "Total"): discard lines which don't match
Derived column to replace the "Total Rows: " with nothing: Leaving just the NNNNNN
dataconversion to convert the string to a number, currently using DT_I4
Aggregate column using SUM
Save to Recordset destination: variable = objRowCountTrailer

The recordset should have only one column and one record which is the value I am looking for: A Data viewer indicates that this is so.

In the Control flow, after the dataflow has written to the object variable I am then using a for-each loop to loop through the values of an ADO Enumerator which is set to the objRowCountTrailer. I have a variable intRowCountTrailer of datatype Int32 which I have mapped to Index 0 of the ADO record set

I am then trying to use this value to pass through to a stored procedure.

When I run the package It fails on the foreach loop and I get the following error messages


Error: ForEach Variable Mapping number 1 to variable "User::intRowCountTrailer" cannot be applied.


Error: The type of the value being assigned to variable "User::intRowCountTrailer" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.


Why am I getting these error messages? I have not tried to map anyting to index 1 and the datatypes should be compatible. I am clearly missing something obvious
HakunaMatata
HakunaMatata
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1212 Visits: 491
Have you tried using DT_Numeric instead of DT_I4?

Rolleyes
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search