开发者

What variable type use to represent a Money in SSIS

开发者 https://www.devze.com 2023-01-21 00:42 出处:网络
I need to load a Money value in a variable in SSIS using a \"Execute SQL Task\" component. I map the return column of a SELECT to a variable.

I need to load a Money value in a variable in SSIS using a "Execute SQL Task" component. I map the return column of a SELECT to a variable. I've declared the variable "UnknownMoney" as a Double or a Single, but i always receive the error:

Error: 0xC00开发者_如何学Go2F309 at Load Dummy vars, Execute SQL Task: An error occurred while assigning a value to variable "UnknownMoney": "The type of the value being assigned to variable "User::UnknownMoney" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.".

The Money column type in SSIS is DT_CY (Currency) but this type is not available for variables.

What's the right type to be used for a Money?

EDIT: the variable type drop down listbox in VS2012:

What variable type use to represent a Money in SSIS

What variable type use to represent a Money in SSIS


SSIS has a currency datatype.

SQL has a money type.

These are compatible.


This is what I would do:

  1. Have the SQL return a type decimal with a Select CAST(MoneyColumn AS decimal(34,8)) FROM Table
  2. Set it to your UnknownMoney of type Decimal
  3. Use your UnknownMoney variable.
  4. If you need to use the variable as a money again, CAST it back into money: CAST(@UnknownMoney AS money)


(Just a little modification of donfolkes's answer)

In SSIS Execute SQL task: select ?=convert(decimal(13,2), MoneyCol). Set the parameters in SSIS and map to UnknowMoney variable, also put the direction as output.

In order to send it back to the SQL convert it again using SQL convert function.

0

精彩评论

暂无评论...
验证码 换一张
取 消