SSIS Converting Percent to Decimal

大城市里の小女人 提交于 2020-01-15 08:17:11

问题


I'm trying to get a percentage to display as a decimal in my database. I have the following set up to convert the percentage columns into decimals:

----------------           ----------------           ------------
excel source     ---------> data conversion ----------> db output
----------------           ----------------           ------------

I've tried to strictly convert the input to decimal and numeric. Neither of these have changed my results.

In my columns in the database I'm getting just 0's and 1's.

Forgive my crude drawing; I do not have enough rep to post pictures yet.


回答1:


Hope this is what you are looking for

Excel sheet like this is the source.

I just tested it in my system.It is working fine. This is what I did.

  1. Created an SSIS package with just 1 DFT.
  2. Data flow is given below. Please note that the value which appeared as 40% in Excel sheet is visible as 0.40. So I added two derived columns. One converting as such and the next which multiplies with 100.

the derived column structure is shown below.

The destination table structure be

Create table Destination
(
id int,
name varchar(15),
hike decimal(8,2)
)

I am getting the result as expected.

Select * from Destination




回答2:


There are many ways to accomplish this. Here's one:

1) Save your excel file as a tab delimited text file.

2) Create a New Flat File Connection in SSIS a) Set File Name = .txt file b) Go to Advanced tab and click on the column with the percentages c) Set the Data Type to match the target field in your database (e.g., numeric(10,5)

3) In the SSIS workflow, create a derived column of your percent field to convert from percent to decimal(e.g., newfield = oldfield/100). Make sure to check the data type has not changed in the Derived Column Transformation Editor.



来源:https://stackoverflow.com/questions/23768482/ssis-converting-percent-to-decimal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!