0

I'm importing data from txt to Sql Server table. That part works good.

Everyday this txt file is being deleted and new txt file is formed (i.e. yesterday there was data for 3 February, today for 4 February (column Date)).

When I run package, I want it to check whether Date column exists in database table. If it exists, skip, don't import, if it doesn't - import. And I want to save that Date value in a variable for further manipulations. How can I accomplish that?

rakamakafo
  • 1,144
  • 5
  • 21
  • 44
  • can you give us more information about the column of your `table `? or your `File` ? – user2460074 Feb 04 '16 at 17:25
  • @downloaddowload, txt file has several columns, one of which is date. And database has exact same number of columns where Date field is of type smalldatetime. Txt File can contain inside it rows with only one date (3rd February or 4th Faebruary and so on, with different times). What kind of information do you actually want me to provide? and just importing values from txt to table works fine. What I want is to set condition, so when I ran package today it imports all values for 4th of February,and if I ran it today second time,it doesn't import anything , since that data already exists in tbl – rakamakafo Feb 04 '16 at 17:34
  • what's is the format of your date ? and also it's store in column with data type is `datetime` ? – user2460074 Feb 04 '16 at 17:36
  • @downloaddowload in txt it is like this 25.01.2016 16:23:14, and in table it is smalldatetime – rakamakafo Feb 04 '16 at 17:37
  • Can you please share how the data is in your file ? – user2460074 Feb 04 '16 at 17:43
  • @downloaddowload, normal tab delimited txt file. for instance, 25.01.2016 16:23:14 ABC XXX ZZZ. How can that help. Maybe I didn't get something, if it necessary I'll attachscreenshot – rakamakafo Feb 04 '16 at 17:58

1 Answers1

1

we suppose you have your source file with the format and data as bellow

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

and your destination have the format as bellow

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

In your SSIS add a Derived Column to convert the smalldatetime to date like this :

Convert smalldatetime to Date

Secondly add a Lookup in General Tab in your Lookup transformation Editor go to Specify how to handle rows with no matching entries and select Redirect rows to no match output. In Connection Tab add a connection to target table and i wrote a Sql query to convert the smalldatetime to date show the picture as bellow :

connection to the target table

In Column tab do this : enter image description here

Finally add a connection with the lookup and your target table and select Lookup no matching output

In the first execution i have 3 rowsinserted because i don't have the date in my table First execution

I execute another time but i had 0 rows because i have the date in my table

enter image description here

I hope that help you

user2460074
  • 1,252
  • 3
  • 11
  • 28