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 |
gyl
Starting Member
1 Post |
Posted - 2005-11-19 : 09:30:15
|
Can anyone help me with this...I'm trying to import excel sheets into a predefined DB table (MSSQL server 2005 Express Ed).My excel files can be stored under different names and into different folders. The sheetnames are not organised into a uniform structure (more than one tables into a sheet).I'm trying to use openrowset therefor but i want to pass variables as argument for it.For example :insertinto Corpus.dbo.tbl_BasicInfosselect * fromopenrowset('Microsoft.Jet.OLEDB.4.0','EXCEL 8.0;Database='+@excelPath+';HDR=NO','SELECT * FROM '+'['+@sheetname+'$]')Answer : Incorrect syntax near '+' (the one before @excelpath in the 2d openrowset argument)Specific cells in the excel sheet have to be passed. I know the syntax for and will also pass then with variables after the sheetname.Thanks ! |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-21 : 01:04:14
|
[code]Declare @excelPath varchar(100)Declare @sheetname varchar(100)Declare @sql varchar(1000)set @excelPath='File Path'set @sheetname='SheetName'Set @sql ='Select * from openrowset(''Microsoft.Jet.OLEDB.4.0'',''EXCEL 8.0;Database='+@excelpath+';HDR=NO'',''SELECT * FROM ['+@sheetname+'$]'')'Exec (@sql)[/code]MadhivananFailing to plan is Planning to fail |
|
|
|
|
|