Solved

SSIS help: Process multiple files

Posted on 2008-10-06
2
521 Views
Last Modified: 2013-11-30
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...

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/Q_23787635.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.

0
Comment
Question by:Pharmica
2 Comments
 
LVL 1

Expert Comment

by:MaxLyd
ID: 22655192
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

0
 

Accepted Solution

by:
Pharmica earned 0 total points
ID: 22668714
MaxLyd:  Thanks for responding, but I was looking for a way to identify each file using a variable, so I can further use that variable to perform other functions on the file (ie, copy it, delete it, move it...etc).  I managed to get this done by using a Foreach loop sequence in SQL BI studio.    Here is the post that solved the problem.

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/Q_23787635.html

0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now