Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | gdawdyStarting Member
 
 
                                        1 Post | 
                                            
                                            |  Posted - 2012-12-17 : 14:45:50 
 |  
                                            | I'm still fairly new to writing SQL scripts. I have a script which imports numerous excel files (possibly reaching 1000+). Some of these Excel spreadsheets have only one row and some have more than 50 rows. I'm importing all of these excel spreadsheets into one table and would like to be able to add a column which identifies which Excel spreadsheet, by filename, the record came from. So rows 1 through 10 may come from ExcelSpreadsheetA.xlsx and rows 11 through 15 may have come from ExcelSpreadsheetB.xlsx. Would I be able to set this identification up during the import process?I use this script to perform my import from excel:select * into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\testing.xls;HDR=YES', 'SELECT * FROM [Sheet1$]')I then have additional statements for each additional Excel spreadsheet which then append to the table.What I would like to do is add logic to the end of that script that says something like:update sqlservertableset filename = testing.xlsBut I want it to set the filename attribute for just the records that had been imported from that specific filename. Ideally I would like the final table to look similar to the one below.Col1   Col2   Col3   Filename=====  =====  =====  =========1      A      B      export1.xlsx2      C      D      export1.xlsx3      E      F      export1.xlsx4      G      H      export5.xlsx5      I      J      export8.xlsx6      K      L      export8.xlsx |  |  
                                    | HommerAged Yak Warrior
 
 
                                    808 Posts | 
                                        
                                          |  Posted - 2013-01-02 : 14:47:09 
 |  
                                          | will this work?select *, 'testing.xls' into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\testing.xls;HDR=YES', 'SELECT * FROM [Sheet1$]') |  
                                          |  |  |  
                                |  |  |  |