July 25, 2002 at 4:10 am
hi folks,
i got to import excelsheets into a ms-sql server db, without using bulkinsert.
the problem that bothers me is, that i need to use dynamic paths, or for now dynamic filenames.
tried simply to use variables in the following manner:
SELECT * INTO table1 FROM OpenRowSet
('MSDASQL', 'Driver= Microsoft Excel Driver (*.xls); DBQ=c:\data\'+@filename+'', 'SELECT * FROM [sheet1$]')
is it possible to use variables to define dynamic paths like this, and if yes what would be the correct code?
thx and fg, andi
July 25, 2002 at 3:27 pm
This is an example of an old file rename that I have that shows you how to build the string and execute it.
/*Rename File.*/
declare
@monthname varchar(32),
@sqlstring varchar(250)
set @monthname = (select datename(month, getdate()))
-- Rename current file to backup file
select @sqlstring = ('exec master..xp_cmdshell ''rename \\ServerName\Path\FileName.XLS FileName_'+@monthname+'''')
exec dbo.sp_executesql
@stmt = @sqlstring
end
David
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply