I have a stored proc which needs to process up to 4 Excel files named Book1.xls, Book2.xls, etc. I am having trouble when, say Book3.xls does not exist. The error I get even stops me at stored procedure compile time if the file is not there! Here is the error text I get trying to issue ALTER PROCEDURE in Query Analyzer:Server: Msg 7399, Level 16, State 1, Procedure _Job_ConvertRawFHAData_PrepareStep, Line 128OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not give any information about the error.OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IDBInitialize::Initialize returned 0x80004005: The provider did not give any information about the error.].Here is a snippet of my technique for which I am seeking an improvement:SET @FileName = 'Book1.xls'SET @File = @Path + @FileNameEXEC master..xp_fileexist @File, @i outIF @i = 1BEGININSERT INTO devmdw.dbo.JJA_02_ExcelSELECT 'PropertyState' = [Property State] , 'PropertyCounty' = [Property County] , 'PropertyZip' = CONVERT(VARCHAR(255),[Property Zip]) , 'OriginatingMortgagee' = [Originating Mortgagee] , 'LenderID' = CONVERT(VARCHAR(255),[Originating Mortgagee Number]) , 'SponsorName' = [Sponsor Name] , 'SponsorID' = CONVERT(VARCHAR(255),[Sponosr Number]) , 'DownPaymentSource' = [Down Payment Source] , 'NonProfitTaxID' = CONVERT(VARCHAR(255),[Non Profit Number]) , 'ProductType' = [Product Type] , 'LoanPurpose' = [Loan Purpose] , 'PropertyProductType' = [Property/Product Type] , 'InterestRate' = Convert(float,[Interest Rate]), 'MortgageAmount' = Convert(int,[Mortgage Amount]) , 'SaleYear' = Convert(int,[Year]) , 'SaleMonth' = Convert(int,[Month]) FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\RawData_MDS\Book1.xls;HDR=Yes;IMEX=1', 'SELECT [Property State] , [Property County] , [Property Zip] , [Originating Mortgagee] , [Originating Mortgagee Number] , [Sponsor Name] , [Sponosr Number] , [Down Payment Source] , [Non Profit Number] , [Product Type] , [Loan Purpose] , [Property/Product Type] , [Interest Rate] , [Mortgage Amount] , [Year] , [Month] FROM [Sheet1$]')ENDSET @FileName = 'Book2.xls'SET @File = @Path + @FileNameEXEC master..xp_fileexist @File, @i out
The line number reference in the error message points to the SET @FileName = 'Book3.xls' statement which is the file that does not exist now (but will exist off and on in the future). Thanks for your time on this.