2016-02-04 28 views
0

我正在将数据从txt导入到Sql Server table。这部分工作很好。SSIS中的实现条件

每天此txt文件被删除,并形成新的txt文件(即昨天有用于2月3日,对于今天2月4日(列Date)数据)。

当我运行包时,我想要它检查数据库表中是否存在Date列。如果它存在,跳过,不要导入,如果它不导入。我想将该日期值保存在variable中以供进一步操作。我怎么能做到这一点?

+0

你能给我们提供关于你的'表'列的更多信息吗?或你的'文件'? –

+0

@ download download,txt文件有几列,其中之一是日期。并且数据库的日期字段的类型为smalldatetime的列数完全相同。 txt文件只能包含一个日期(2月3日或4月2日等等,不同时间)。你真的希望我提供什么样的信息?只是从txt导入值到表格工作正常。我想要的是设置条件,所以当我今天运行包时,它会导入2月4日的所有值,如果我今天第二次运行它,它不会导入任何内容,因为该数据已经存在于tbl – Sher

+0

什么是你约会的格式?并且它的数据类型是'datetime'? –

回答

1

我们假设你有格式和数据作为波纹管

id | product   | dateLoad 
1  | dell   | 25-01-2016 16:23:14 
2  | hp    | 25-01-2016 16:23:15 
3  | lenovo   | 25-01-2016 16:23:16 

和你的目的地的格式源文件为波纹管

create table stack(id int,product varchar(20),dateLoad smalldatetime); 

在你SSIS添加Derived Columnsmalldatetime转换到date像这样:

Convert smalldatetime to Date

其次在添加LookupGeneral标签您Lookup transformation EditorSpecify how to handle rows with no matching entries和选择Redirect rows to no match output。在Connection选项卡添加一个连接到目标table,我写了一个Sql query转换的smalldatetime to date显示图片波纹管:

connection to the target table

Column tab做到这一点: enter image description here

最后补充与连接lookup和您的target table并选择Lookup no matching output

在第一个exec ution我有3 rows插入,因为我没有时间在我的表 First execution

我执行另一个时间,但我不得不0 rows,因为我有我的table

enter image description here

我希望日期帮助你

+0

谢谢你的详细解释。这很有效 – Sher

+0

还有一个问题:我如何在变量中保存日期。我想在发送邮件任务中使用如下主题:“Info for 04/02/2016。预先感谢 – Sher

+1

你想在我的例子中''variable'中的文件中存在的日期是'25-01- 2016'' –