English 中文(简体)
如何使用SSIS将固定的宽度平档输入数据库?
原标题:How to import a fixed width flat file into database using SSIS?

是否有任何人对如何使用SSIS一揽子计划向数据库输入固定的湿度假档案进行辅导?

我有一个固定的档案,有几长的栏目。

Column name    Width
-----------    -----
First name        25
Last name         25
Id                 9
Date               8

我如何将一个固定档案转换成一栏?

最佳回答

这里是利用SSIS 2008 R2制作的一套样本,说明如何将一个固定档案输入数据库表。

  • Create a fixed-width flat file named Fixed_Width_File.txt with data as shown in the screenshot. The screenshot uses Notepad++ to display the file contents. It has the capability to show the special characters like carriage return and line feed. CR LF denotes the row delimiters Carriage return and Line feed.

Flat file data

  • In the SQL server database, create a table named dbo.FlatFile using the create script provided under SQL Scripts section.

  • 创建新的SSIS一揽子计划,并增加一个新的OLE DB联系管理人,与SQ服务器数据库连接。 让我们假设,OLE DB联系管理人的名字是SQLServer

Connection manager

  • On the package s control flow tab, place a Data Flow Task.

Data flow task

  • 关于数据流动任务的双轨数据,将输入数据流动表。 关于数据流表,请登陆Flat文档<>。 统一档案来源和Flat文档来源编辑<>m>上的双立影印本。 www.un.org/spanish/ga/president 法文版

  • 关于Flat文档来源主编的一般部分,在Connection Manager name(saySource)和浏览到统一档案地点并选择档案。 这一例子在<条码>C: empFixed_Width_File.tx中使用了样本文档。 如果你在案卷中拥有头盔,你可以把头角的数值一输入,以绕过文字箱,跳出头角。

“Flat文档链接总经理”。</p

  • Click on the Columns section. Change the font according to your choice I chose Courier New so I could see more data with less scrolling. Enter the value 69 in the Row width text box. This value is the sum of width of all your columns + 2 for the row delimiter. Once you have set the correct row width, you should see the fixed width file data correctly on the Source data columns section. Now, you have to click at the appropriate locations to determine the column limits. Note the sections 4, 5, 6 and in the below screenshot.

“Flat文档链接管理员Columns”/

  • Click on the Advanced section. You will notice 5 columns created for you automatically based on the column limits that we set on the Columns section in the previous step. The fifth column is for row delimiter.

“Flat文档链接编辑高级”</p

  • Rename the column names as FirstName, LastName, Id, Date and RowDelimiter

“Flat文档链接管理员</p

  • By default, the columns will be set with DataType string [DT_STR]. If we are fairly certain, that a certain column will be of different data type, we can configure it in the Advanced section. We will change Id column to be of data type four-byte signed integer [DT_I4] and Date column to be of data type date [DT_DATE]

“Flat文档链接管理员高级一栏”</p

“Flat文档链接管理员高级日期栏”</p

  • Click on the Preview section. The data will be shown as per the column configuration.

Flat file connection manager editor Preview

  • Click OK on the Flat file connection manager editor and the flat file connection will be assigned to the Flat File Source in the data flow task.

“Flat文档编辑链接”</p

  • On the Flat File Source Editor, click on the Columns section. You will notice the columns that were configured in the flat file connection manager. Uncheck the RowDelimiter because we won t need that.

“Flat档案编辑栏”/

  • On the data flow task, place an OLE DB Destination. Connect the output from the Flat file source to the OLE DB Destination.

“Data

  • On the OLE DB Destination Editor, select the OLE DB Connection manager named SQLServer and set the Name of the table or the view drop down to [dbo].[FlatFile]

“OLE

  • On the OLE DB Destination Editor, click on the Mappings section. Since the column names in the flat file connection manager are same as the columns in the database, the mapping will take place automatically. If the names are different, you have to manually map the columns. Click OK.

“OLE

  • Now the package is ready. Execute the package to load the fixed-width flat file data into the database.

“Package

  • If you query the table dbo.FlatFile in the database, you will notice the flat file data imported into the database.

https://i.stack.imgur.com/KsTCp.png” alt=“Data import into table”/>

这一样本应使您了解如何将固定宽度的固定档案输入数据库。 它没有解释如何处理错误的伐木,但这应该让你开始,帮助你发现其他与信息社会首脑会议有关的特征。

希望会有所帮助。

<><><><Ros>:>

CREATE TABLE [dbo].[FlatFile](
    [Id] [int] NOT NULL,
    [FirstName] [varchar](25) NOT NULL,
    [LastName] [varchar](25) NOT NULL,
    [Date] [datetime] NOT NULL
)
问题回答

In the derived column transformation you can use SUBSTRING() function for each of the column. Example:

Columns DerivedColumn

FirstName SUBING(Data,startFrom, Length);

在这里,第一夫人有25人,如果我们认为,从上列第0位的位置来看,你应该通过提供SUBSTRING(Data, 0, 25);

同样,其他栏目也是如此。

Siva! 你的理论和出色的插图指出,微软本应明确指出哪些内容。

  1. that the width for a fixed length row has to include the Carriage Return and Line Feed (CR & LF) characters (which I figured out because the preview showed the rows were not lining up correctly)
  2. the all important step of defining an extra column to contain those CR & LF characters, even though they won t be imported. I figured this out, too. I would have benefited by finding your answer before I began.

Without those two things, an attempt to run the import will give this error message: The data conversion for column "Column x" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".

我在这份错误案文中补充说,希望有人在寻找错误原因时找到这一页。 即便在事实之后,你也值得tur。





相关问题
Transform date represented as String to Date in Visual Basic

I am using SSIS and I need to transform a date. How can I transform a date in String format (e.g. 14/09/1980) to the same but in date format in VB.NET? I would like the datetime format to insert it ...

SSIS Script Task connecting to AD

I have written a SSIS 2005 script task that connects to Active Directory and reads user accountnames to store in database. I was able to successfully test this on my local system by executing dtexec....

ssis sql server 2008 for access .mdb database

I want to know how to import .mdb (MS Office 07) file into Sql server 2008 by SSIS. I need to run this ETL packet in such a way that it checks for duplicates, and if any doesnt re-insert them, but ...

parent package in SSIS

I need to execute 29 ssis packages. So planning to create one master package which will execute all these packages. I don t know how to implement this. Can you please explain in brief. Thanks in ...

SQL Agent not kicking off an SSIS package

I have a server that has a SQL Agent job setup to run a two part datawarehouse build and Analysis Services cube build. The job ran successfully until there was a problem with Management Studio and ....

Can SSIS ScriptTask References resolve to a non GAC location?

In SSIS 2008, the ability to reference other class libraries has been added. Is there anyway to resolve the references to a non-GAC location when deployed to a non-developer environment? For instance, ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...