whateveragain
Programmer
I want users to be able to upload data from either a text file or XLS file. Below I'm using an example for XLS. Whether I write code to upload a text file or an Excel file. I keep getting the following error:
" ErrorCode=-2146232060
LineNumber=1
Message="Incorrect syntax near 'c:'. in importdirectories"
The filename imports into the stored procedure importdirectories just fine. Both the temporary and permanent tables are created, but data will not import and I get the error mentioned above. Any ideas?
ALTER PROCEDURE importdirectories
(
@Impfilename Char(30), -- user types in file name they want to import from their desktop
@MyId VarChar(50)
)AS
BEGIN
Declare @mydirs varchar(55) = 'mydirectories' + ltrim(rtrim(@MyId))
declare @SQL varchar(1000)
create table #mydirectories -- dump data into a table
(dircode integer)
-- My Excel import statement
set @sql = 'Insert into #mydirectories Select * FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database='''+ @Impfilename +''';HDR=YES'',''SELECT * FROM [Sheet1$]'')';
exec(@SQL)
-- My text import statement
set @SQL = 'SELECT * INTO #mydirectories FROM OPENROWSET(BULK N'''+@Impfilename+''', SINGLE_BLOB) as dircode' --no error but doesn't work
-- Another text import statement - same error as above 'incorrect syntax near 'c:'
SET @sql = 'BULK INSERT #mydirectories FROM ' + @Impfilename +' WITH (ROWTERMINATOR = ''' + CHAR(10) + char(13) + ''')'
exec(@SQL)
exec('Select * into ' + @mydirs + ' from #mydirectories') -- copy from temp table to permanent table
" ErrorCode=-2146232060
LineNumber=1
Message="Incorrect syntax near 'c:'. in importdirectories"
The filename imports into the stored procedure importdirectories just fine. Both the temporary and permanent tables are created, but data will not import and I get the error mentioned above. Any ideas?
ALTER PROCEDURE importdirectories
(
@Impfilename Char(30), -- user types in file name they want to import from their desktop
@MyId VarChar(50)
)AS
BEGIN
Declare @mydirs varchar(55) = 'mydirectories' + ltrim(rtrim(@MyId))
declare @SQL varchar(1000)
create table #mydirectories -- dump data into a table
(dircode integer)
-- My Excel import statement
set @sql = 'Insert into #mydirectories Select * FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database='''+ @Impfilename +''';HDR=YES'',''SELECT * FROM [Sheet1$]'')';
exec(@SQL)
-- My text import statement
set @SQL = 'SELECT * INTO #mydirectories FROM OPENROWSET(BULK N'''+@Impfilename+''', SINGLE_BLOB) as dircode' --no error but doesn't work
-- Another text import statement - same error as above 'incorrect syntax near 'c:'
SET @sql = 'BULK INSERT #mydirectories FROM ' + @Impfilename +' WITH (ROWTERMINATOR = ''' + CHAR(10) + char(13) + ''')'
exec(@SQL)
exec('Select * into ' + @mydirs + ' from #mydirectories') -- copy from temp table to permanent table