2

Hi how do i read file with dynamic filename? In ssis for importing csv data to my database.

The csv file naming convention can be like: File-ddmmyyyyhhmmss.txt

can anyone advise?

1

3 Answers 3

1

Steps for dynamically load the flat file into the destination.

  • Use the Foreach loop container
  • In Collection tab, Select Enumerator as Foreach File Enumerator and Configure as follows.

Folder: Location of your source files

Files : File-*.txt [Since your file naming is something like File-ddmmyyyyhhmmss.txt]

Retrive File Name : Select Fully qualified Name [which brings entire location of your file]

enter image description here

  • In Variable Mapping, Create a variable to store the Full file path and configure as shown in the screenshot.

enter image description here

  • Create a Flat file connection using sample file.
  • Select a Flat file and go to properties. Find the expression property and map the variable to the connection string as shown in the following screenshot. enter image description here

Important Note:

If you want to validate the file name and existence of the file name before loading into the destination table. Use the script component inside the For each loop container and validate.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Here's a step by step guide

  1. Use the Foreach Loop Container (File Enumerator type) , set your Files mask as File-??????????????.txt
  2. Map a string variable to capture the match files.
  3. Add a Script Task inside this container to parse the string variable to match the actual file naming convention (hint: use regex). Any successful matches will act like a filter larger list of files found by the Foreach Loop Container.

Comments

0

Refer this learning series from Microsoft:

https://learn.microsoft.com/en-us/sql/integration-services/lesson-2-adding-looping-with-ssis?view=sql-server-2017

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.