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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • AWStats日志分析

    AWStats日志分析AWStats日志分析系统介绍1.AWStats日志分析系统(1)Peri语言开发的一款开源日志分析系统(2)可用来分析Apache、Samba、Vsftpd、IIS等服务器的访问日志(3)信息结合crond等计划任务服务,可对日志内容定期进行分析部署AWStats日志分析系统1.安装AWStats软件包2.为要统计的站点建立配置文件3.修改站点统计配置文件…

    2022年7月16日
    23
  • navicat生成激活码错误(注册激活)[通俗易懂]

    (navicat生成激活码错误)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年3月28日
    586
  • 网线RJ45接口排线示意图(做网线备用)「建议收藏」

    网线RJ45接口排线示意图(做网线备用)「建议收藏」网线RJ45接口排线示意图(做网线备用)RJ45有两种绕线方式,T-568A和T-568B。注意:绝大多数设备用的都是T-568B!!!请参照T-568B的线序!!!我的热门文章推荐多路视频直播用在线云导播切换的效果测试 如何把视频转换生成二维码,扫码直接播放? 有哪些网站上传视频是不会插入广告的? 怎么把视频生成二维码?微信扫二维码就可以观看?不要广告的 常用照片尺寸对照表,照片大小看这个表就对了 视频直播推流攻略(整理的各大平台推流界面) html5视频倍.

    2022年9月17日
    7
  • matlab int8 矩阵,unit8_matlab数据类型转换——int8转换成unit8「建议收藏」

    matlab int8 矩阵,unit8_matlab数据类型转换——int8转换成unit8「建议收藏」在一个驱动程序中看到uint16,uint32,unit8,int8…uint16:无符号16bit整数,uint32:无符号32bit整数,unit8:无符号8bit整数,int8:有符号8bit整数。其作用是程序更加简洁,增强可移植性和可维护性,尤其是在16位机器,32位,或者是64位机器上相互之间移植的时候只需要修改这些宏定义就可以满足要求了,而不需要去修改整个工程里边的每一个变量定义…

    2022年9月17日
    1
  • 香农编码的matlab实现总结_matlab简单代码实例

    香农编码的matlab实现总结_matlab简单代码实例用MATLAB编程实现香农编码实验四、用MATLAB编程实现香农编码⒈实验目的和要求(1)了解信源变长码的编码方法(2)掌握香农编码方法(3)掌握MATLAB的编程⒉实验主要内容使用MATLAB语言和excel对以下信源进行香农编码,并求出平均码长和编码效率。3.实验原理Ⅰ.香农编码方法将信源发出的N个消息符号按其概率的递减次序排列按下式计算第个消息的二进制代码组的码长,并取整计算第个消息的累加概…

    2022年9月10日
    5
  • 关于UDP接收icmp端口不可达(port unreachable)

    关于UDP接收icmp端口不可达(port unreachable)本篇分为3部分1:报文格式2:产生的原因3:linux协议栈如何处理4:应用层如何获取1:报文如下,10.30.13.1往10.30.16.10的80端口发送了一个UDP报文,80端口其实监听的是TCP。服务器回复了一个类型为端口不可达的ICMP,ICMP数据部分就是请求UDPip层及其以上的数据。2:原因首先原因就是接收udp报文…

    2022年7月12日
    15

发表回复

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

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