简体   繁体   English

带条件拆分的SSIS检查日期格式

[英]SSIS Check date format with conditional split

I have a flat file that with a "date" column. 我有一个带有“日期”列的平面文件。 The problem is that date could come in as 问题是日期可能会输入

01-Jan-16 or 01-Jan-16

01Jan2016

If I run this in a derived column 如果我在派生列中运行

(DT_DBDATE)(SUBSTRING(bene_dob,1,2) + "-" + SUBSTRING(bene_dob,3,3) + "-" + SUBSTRING(bene_dob,7,4))

it handles the second date fine, but really screws up the first date. 它可以很好地处理第二个日期,但实际上会弄乱第一个日期。

I'm trying to deal with this thru a conditional split, but I'm not sure how to proceed. 我正在尝试通过条件拆分来解决此问题,但是我不确定如何继续。

How do I verify that date format in a conditional split? 如何验证条件拆分中的日期格式?

Or if you have an alternative suggestion, I'm open to ideas. 或者,如果您有其他建议,我欢迎您提出意见。

Thanks 谢谢

一种快速而肮脏的方法是对日期列进行规范化 ,因此将其除去不需要的字符(在这种情况下为“-”),然后应用派生的列表达式,如下所示:

(DT_DBDATE)(SUBSTRING(REPLACE(bene_dob, "-", ""),1,2) + "-" + SUBSTRING(REPLACE(bene_dob, "-", ""),3,3) + "-" + SUBSTRING(REPLACE(bene_dob, "-", ""),7,4))

Replace the dashes with an empty string before the derived column so that all rows will have the same format (01Jan2016). 在派生列之前用空字符串替换破折号,以便所有行都具有相同的格式(01Jan2016)。 You'll also need to add the first 2 digits of the year if they are missing. 如果缺少年份的前两位数字,则还需要添加它们。

Or if you really want to use a conditional split, just test for the presence of the hyphen character and split based on whether it is in the string or not. 或者,如果您真的想使用条件拆分,则只需测试是否存在连字符,然后根据是否在字符串中进行拆分。

在进行进一步处理之前,我将所有日期格式转换为相同格式,可以通过sql或sis中的数据转换来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM