I've got some sql returning a decimal(20,0) data type. In SSIS I have a package with a foreach loop. In my variable mappings, what type of variable would I map it to? I've tried Int32, Int64, double, and still get the error "The type of the value being assigned to variable "User::iID" differs from the current variable type..."
.NET decimal has methods decimal.ToInt64(), decimal.ToInt32() etc.
A SQL decimal(20,0) has a precision of 20 which equates to 13 bytes of storage. The .Net decimal is 16 bytes and should work.
SSIS does have Decimal and Numeric types. You can use either of these and it'll go through (except maybe on a Union All, where you should make sure they're the same precision and scale).
See more about data types here.
Clarifying the question: The person asking the question wants to store a value of type decimal(20,0) in an SSIS variable - not a variable in a .NET script, but a variable tied to a package or container, as created in SSIS itself. I have a similar problem....
You would need to convert the SQL data type to an Int64 prior to putting it into a Int64 package variable.
How are you getting it, as an output parameter?
In a dataflow, you would obviously read it into a decimal/numeric and then convert to Int64 in a Data Conversion component.
If you're trying to directly map an output parameter from an Execute SQL Command task, you'll probably have to use a temporary object package variable and then convert it in a script task into the real Int64 package variable.
The SSIS variable designer did not, in my case, show the Decimal or Numeric data types to select to place my decimal(18,2) value into.
I changed my variable to Object, and was able to read the Decimal(18,2) value from the result set of one stored proc, and pass it as a parameter with type Money to a second SP.
So I would use "Object" if you cannot find a type in the variable list that works for you.