Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Use Database table to dynamically get the excel filename Expand / Collapse
Author
Message
Posted Wednesday, September 10, 2008 7:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 21, 2008 8:02 AM
Points: 10, Visits: 42
I'm trying to build a package that loads a sheet from excel into SQL Server table. Each of our locations submits a file to the network. However some locations will go away and others may be added so I wanted to make the filename list table driven. I have the data flow working that successfully loads the spreadsheet but now I'm looking for a method to get the excel filename from a table. I was testing with the execute sql .

Thanks for any help
Richard
Post #566867
Posted Wednesday, September 10, 2008 11:26 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 25, 2014 11:07 AM
Points: 226, Visits: 723
Use expression to set the connection string for your excel connection. Use a variable to set the conection string. You can do this by Properties->Expressions->ExcelFilePath-> Set your vairble here.

Now use Execute SQL Task to set the value of this variable. In the Execute SQL Task Editor, set the ResultSet as SingleRow, now click on Result Set on the side menu and click Add to add a vairble mapping. If you are uisng OLEDB conneciton use 0 as Resultset name and select your variable.
This should set the variable to a value from your table and will set the Excel File Path for excel to this value.

HTH
Mukti
Post #567142
Posted Wednesday, September 10, 2008 12:42 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, December 14, 2009 2:47 PM
Points: 11, Visits: 50
The way that I've done this successfully in the past was to use the expressions to replace the Excel Filename property with the filename from some variable.

My observation has been that the connection string property for a spreadsheet does not ever contain a filename, even when using a static filename. (but that is not to say that SSIS does not add the filename property to the connection string at runtime to produce it.

At least that how i've done it in a ForEach container and it has always worked. Never had to do anything with the connect string property, only the filename property.

Post #567216
Posted Wednesday, September 10, 2008 2:52 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 21, 2008 8:02 AM
Points: 10, Visits: 42
what enumerator type did you use in the foreach loop
Post #567317
Posted Wednesday, September 10, 2008 3:45 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 25, 2014 11:07 AM
Points: 226, Visits: 723
Excel connection has the ExcelFilePath that you can set dynamically. (Edited by previous answer too).

Use the File Enumerator in ForEach loop.
Post #567341
Posted Friday, September 12, 2008 10:11 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 21, 2008 8:02 AM
Points: 10, Visits: 42
Thanks for the help so far but the for each does not seem to make sense. Once I make the setting foreach file, it now reads each file in the directory. I want it to get the filename from the database select which brings back more than one row.

Richard
Post #568699
Posted Friday, September 12, 2008 1:51 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 21, 2008 8:02 AM
Points: 10, Visits: 42
Reading on in the help about the exec sql task it says if you bring back more than one row you must define a variable of type object , then use script to extract the data. I'm now confused on how the orginal suggestion in his post could work.

Any help appreciated.

Thanks
Post #568906
Posted Friday, September 12, 2008 3:34 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 21, 2008 8:02 AM
Points: 10, Visits: 42
I just gave up and used the normal file load
Post #568970
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse