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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 虚拟机配置DNS服务器「建议收藏」

    虚拟机配置DNS服务器「建议收藏」虚拟机配置DNS服务DNS简介下面演示如何通过虚拟机安装DNS服务器windows2003(DNS服务端)安装DNS服务客户端做相应配置回到windows2003新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML图表FLowchart流程图导出与导入导出导入DNS简介

  • string和stringstream用法详解「建议收藏」

    string和stringstream用法详解「建议收藏」一、stringstring 是C++提供的字串型態,和C的字串相比,除了有不限长度的优点外,还有其他许多方便的功能。要使用 string,必須先加入这一行:#include接下來要宣告一个字串变量,可以写成:strings;我们也可以在宣告的同时让它设成某个字串:strings=”TCGS”;而要取得其中某一個字元,和传统C的字串

  • db4o的使用

    db4o的使用from:http://www.ibm.com/developerworks/cn/java/j-lo-db4o2/index.html前言在 db4o之旅 系列文章的第一部分:初识db4o 中,作者介绍了db4o的历史和现状,应用领域,以及和ORM等的比较。在这篇文章中,作者将会介绍db4o的安装、启动以及三种不同的查询方式:QBE(QuerybyEx

  • Qt中的角度转弧度[通俗易懂]

    Qt中的角度转弧度[通俗易懂]在Qt中,qAsin(),qAtan2()等三角函数的返回值是弧度而不是角度,因此要将弧度转化为角度。弧度=角度*Pi/180以qAtan()函数为例qrealqAtan(qrealv)Returnsthearctangentofvasanangleinradians.Arctangentistheinverseoperationoftangent….

  • laravel5.6 QQ 第三方登录

    laravel5.6 QQ 第三方登录

    2021年10月25日
  • 几个vbs代码

    几个vbs代码使用方法:新建一个txt文档,将上面的代码复制到txt,然后将文档的后缀名改成vbs。鼠标双击即可执行。第一个:msgbox”做我女朋友好吗”,vbQuestion,”在吗”msgbox(“房产写你名字”)msgbox(“保大”)msgbox(“我妈会游泳”)dimjdowhilej<1SelectCasemsgbox(“做我女朋友好吗”,68,”请郑重的回答我”)Case6j=1Case7msgbox(“再给你一次机会”)endSelect

发表回复

您的电子邮箱地址不会被公开。

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