Link to home
Start Free TrialLog in
Avatar of Pharmica
PharmicaFlag for Afghanistan

asked on

SSIS help: Process multiple files

Greetings Experts,

I have posted this question before but onobody has responded in a few days and I need to resolve ASAP.  You can see the original post here...

https://www.experts-exchange.com/questions/23787635/SQL-SSIS-issue-How-to-Process-multiple-files-with-different-names.html

I have this SSIS package that takes an Excel file (enrollment.xls) from a server share and imports it into a SQL database, then it deletes it from the server share.  The idea is that someone will create this enrollment-STUDYNAME.xls file and place it on the server share to be processed.  However, the problem with this approach is that there can only be one file in that location at any given time.  How do I go about programming the SSIS package to look for every file in the folder and process each?  The file does not need to be called enrollment.xls.... it can enrollment1.xls, enrollmentB.xls.   This way people can pop as many files in there to be processed and I can then schedule this SSIS package to run at night.

Avatar of MaxLyd
MaxLyd

Interesting question.  This isn't a perfect solution, but it's what I would do...

Have people save the files on the share drive during the day and have some sort of cut-off when people aren't supposed to save any new files (more of an operations  issue).
 
Then write a small batch file to copy all the .xls (or whatever they are) files to the same drive under a uniform name which can be overwritten each night.  (code snippet)  You can easily schedule this within windows scheduler to run at whatever time you want.  You just need to make sure you have the correct permissions.
You can then have a linked server setup using that file through SQL server management studio.  This will allow you to query that file like a table. Not sure if that is what you had set up already with the existing import...  I find it to be the most versatile way to import data because it allows for a lot of data manipulation prior to insertin the data into tables.  Kind of takes the necessity of temp tables out of the equation a lot of times.
The only thing you will have to be concious of is that the fields will have to be EXACTLY the same in the files that are to be combined.  This is because the batch file with merely mush the data together (yup that means field names and all).  So you will have to take that into account when you are setting up the SSIS package to exclude those rows of data.

COPY \\somedrivename\*.xls "\\somedrivename\Linkedspreadsheet.xls" /Y 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pharmica
Pharmica
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial