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


相关推荐

  • moxa串口服务器网页版用户名密码,moxa串口服务器设置密码

    moxa串口服务器设置密码内容精选换一换登录Windows操作系统的弹性云服务器时,需使用密码方式登录。因此,用户需先根据创建弹性云服务器时使用的密钥文件,获取该弹性云服务器初始安装时系统生成的管理员密码(Administrator帐户或Cloudbase-init设置的帐户)。该密码为随机密码,安全性高,请放心使用。请根据您的个人需求,通过管理控制台或API方式获取Windo登录Windows…

    2022年4月6日
    131
  • 在线网站技术分析工具

    在线网站技术分析工具Wappalyzer:在线网站技术分析工具Wappalyzer网站是一个可以分析不同网站所使用的各种技术的工具,对于有自身经验的网站开发者而言可以通过代码开分析网站的构架和所采用的技术,不过现在你可以通过工具来获得网站技术的参数报告了。Wappalyzer工具致支持分析目标网站所采用的平台构架、网站环境、服务器配置环境、JavaScript框架、编程语言等参数,同时

    2022年5月4日
    46
  • win10电脑设置提醒任务_win10添加计划任务

    win10电脑设置提醒任务_win10添加计划任务博主公司周报漏交一次要缴纳50RMB部门经费,另外博主每天上午下午都需要活动10分钟(好像放风。。),防止职业病+让自己的工作状态更好。步骤:1、打开Win10控制面板—>点选管理工

    2022年8月2日
    7
  • 怎么html文字下划线,HTML怎么设置下划线?html文字加下划线方法

    怎么html文字下划线,HTML怎么设置下划线?html文字加下划线方法HTML中的下划线曾经是将文本包含在标签中的问题,但是这种方法已被放弃,而更倾向于使用更多功能的CSS。一般来说,下划线被认为是引起人们对文本注意的一种方式,那么HTML怎么设置下划线?html文字加下划线方法?下面我们来总结一下。1.使用“text-decoration”CSS样式属性,使用标签不再是强调文本的正确方法。而是使用“text-decoration”CSS属性,语法为:<sp…

    2022年6月3日
    44
  • Java Random nextInt()方法与示例[通俗易懂]

    Java Random nextInt()方法与示例[通俗易懂]随机类nextInt()方法(RandomClassnextInt()method)Syntax:句法:publicintnextInt();publicintnextInt(intnum);nextInt()methodisavailableinjava.utilpackage.nextInt()方法在java.util包中可…

    2022年7月22日
    8
  • day 08 String类、Random类、ArrayList类

    day 08 String类、Random类、ArrayList类

    2021年5月19日
    130

发表回复

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

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