smalldatetime java,如何在数据导入期间将平面文件中的dd-mmm-yy值格式化为smalldatetime?…[通俗易懂]

smalldatetime java,如何在数据导入期间将平面文件中的dd-mmm-yy值格式化为smalldatetime?…[通俗易懂]IhaveaflatfilewhichisimportedintoSQLServerviaanexistingSSISpackage.Ineedtomakeachangetothepackagetoaccommodateanewfieldintheflatfile.Thenewfieldisadatefieldwhi…

大家好,又见面了,我是你们的朋友全栈君。

smalldatetime java,如何在数据导入期间将平面文件中的dd-mmm-yy值格式化为smalldatetime?...[通俗易懂]

I have a flat file which is imported into SQL Server via an existing SSIS package. I need to make a change to the package to accommodate a new field in the flat file. The new field is a date field which is in the format dd-mmm-yy (e.g. 25-AUG-11). The date field in the flat file will either be empty (e.g. a space/whitespace) or populated with a date. I don’t have any control over the date format in the flat file.

I need to import the date field in the flat file into an existing SQL Server table and the target field data type is smalldatetime.

I was proposing to import the date as a string into a load table and then convert to smalldatetime when taking the data from the load table. But is there another possible way to parse the date format dd-mmm-yy to load this straight into a smalldatetime field without having to use convert to smalldatetime from the load table. I can’t quite think how to parse the date format, particularly the month. Any suggestions welcome.

解决方案

Here is an example that might give you an idea of what you can do. Ideally, in an SSIS package or in any ETL job, you should take into account that data may not be exactly what you would like it to be. You need to take appropriate steps to handle the incorrect or invalid data that might pop up now and then. That’s why SSIS comes up with lots of Transformation tasks within Data Flow Task which you can make use of to clean up the data.

In your case, you can make use of Derived Column transformation or Data conversion transformation to achieve your requirements.

The example was created in SSIS 2008 R2. It shows how to read a flat file containing the dates and load into an SQL table.

iMPG7.png

I created a simple SQL table to import the flat file data.

AMYy3.png

On the SSIS package, I have a connection manager to SQL and one for Flat file. Flat file connection is configured as shown below.

wHYja.png

4gY8N.png

rLQX5.png

m78d2.png

On the SSIS package, I placed a Data Flow Task on the Control Flow tab. Inside, the Data Flow task, I have a Flat File Source, Derived Column transformation and an OLE DB Destination. Since the Flat file source and OLE DB destination are straightforward, I will leave those out here. The Derived transformation creates a new column with the expression (DT_DBDATE)SmallDate. Note that you can also use Data Conversion transformation to do the same. This new column SmallDateTimeValue should be mapped to the database column in OLE DB Destination.

Tnr8M.png

If you execute this package, it will fail because not all the values in the file are valid.

902ep.png

The reason why it fails in your case is because the invalid data is directly inserted into the table. In your case, the table will throw an exception making the package to fail. In this example, the package fails because the default setting on the Derived column transformation is to fail the component if there is any error. So, let’s place a dummy transformation to redirect the error rows. We will Multicast transformation for this purpose. It won’t really do anything. Ideally, you should redirect the error rows to another table using OLE DB Destination or other Destination component of your choice so you can analyze the data that causes the errors.

Drag the red arrow from Derived transformation and connect it to the Multicast transformation. This will popup the Configure Error Output dialog. Change the values under the column Error and Truncation from Fail component to Redirect row. This will redirect any error rows to the Multicast transformation and will not get into the tables.

SOaLm.png

Now, if we execute the package, it will run successfully. Note the number of rows displayed in each direction.

ysZwu.png

Here is the data that got into the table. Only 2 rows were valid. You can look at the first screenshot that showed the data in the file and you can see only 2 rows were valid.

Hope that gives you an idea to implement your requirement in the SSIS package.

5P9mp.png

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/144398.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月19日 下午5:20
下一篇 2022年5月19日 下午5:40


相关推荐

  • MIUI解BL锁失败[通俗易懂]

    MIUI解BL锁失败[通俗易懂]最后解决办法是:换USB2.0接口分析问题:或许可能是软件兼容性不好,USB3.0影响读取设备信息,导致无法解锁。

    2022年5月27日
    87
  • 需求分析说明书SRS

    需求分析说明书SRS软件需求分析说明书 1 引言 1 1 编写目的本文档的目的是详细地介绍停车场管理系统所包含的需求 以便客户能够确认产品的确切需求以及开发人员能够根据需求设计编码 以下叙述将结合文字描述 流程图来描述停车场管理系统的功能 性能 运行环境 1 2 系统概述使用停车场管理系统 在停车场的出入口设置一套出入口管理设备 使停车场形成一个相对封闭的场所 用户进出停车场只需将注册个人信息并扫描二维码 系统即能瞬时完成检验 记录 核算 收费等工作 挡车道闸自动启闭 方便快捷地进行着停车场的管理 对出口管理员来讲

    2026年3月17日
    2
  • access数据库表的创建_access数据库sql语句大全

    access数据库表的创建_access数据库sql语句大全在Access中使用sql语句创建表时指定字段类型长度为255的文本varchar长度为20的文本varchar(20)日期时间datetime数字byte或smallint或integer,或bit自动编号:counter(1,1)外健:constraint外健名主键:primarykey小数:numeric单精度:real双精度:float备注:m

    2022年10月9日
    3
  • 完整教程:【AI编程实战】零基础用ChatGPT+Cursor开发完整Web应用:30分钟从idea到上线

    完整教程:【AI编程实战】零基础用ChatGPT+Cursor开发完整Web应用:30分钟从idea到上线

    2026年3月16日
    2
  • OleDbCommand类[通俗易懂]

    OleDbCommand类[通俗易懂]首先,建立一个OleDbCmdTest.aspx代码如下:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="OleDbCmdTest.aspx.cs"Inherits="OleDbCmdTest"%><!DOCTYPE

    2022年5月20日
    41
  • HTML中的setCapture和releaseCapture

    HTML中的setCapture和releaseCapturesetCapture函数的作用就是将后续的mouse事件都发送给这个对象,releaseCapture就是将鼠标事件还回去,由document、window、object之类的自行来处理。这样就保证了在拖动的过程中,不会由于经过了其它的元素而受到干扰。另外,还有一个很重要的事情是,在Win32上,mousemove的事件不是一个连续的,也就是说,并不是我们每次移动1px的鼠标指针,就会发…

    2022年6月4日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号