G12Consult
Programmer
Hi,
I have the following SP which I am trying to use to import the contents of an excel file.
I am receiving the 'file does not exist' error. No records are being added to the table.
To execute I am using
With 'master' being the sheet name and 'ExcelData' being the table
I have the following SP which I am trying to use to import the contents of an excel file.
Code:
ALTER PROCEDURE [dbo].[spImportExcelFile]
(@Source varchar(1000)
, @SourceSheet varchar (100)
, @DestinationTable varchar (100))
AS
BEGIN
SET NOCOUNT ON
declare @retval int
EXEC master..xp_fileexist @Source, @retval output -- check if file exists
if @retval = 0
begin
print 'file does not exist.'
return
end
if @SourceSheet is null or @SourceSheet = ''
set @SourceSheet = '[Master$]'
else
set @SourceSheet = '[' + ltrim(rtrim(@SourceSheet)) + '$]'
if @DestinationTable is null or @DestinationTable = ''
set @DestinationTable = substring(@SourceSheet, 2, len(@SourceSheet) - 3) + convert(varchar, getdate(), 126)
exec('select * into [' + @DestinationTable + '] from openrowset
(''Microsoft.Jet.OLEDB.4.0'', ''Excel 8.0;HDR=YES;Database=' + @Source + ''', ' +
@SourceSheet + ')')
END
I am receiving the 'file does not exist' error. No records are being added to the table.
To execute I am using
Code:
exec spImportExcelFile 'C:\Users\Andrew\Desktop\Junior_DB.xls','Master','ExcelData'
With 'master' being the sheet name and 'ExcelData' being the table