SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 openrowset arguments
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/19/2005 :  09:30:15  Show Profile  Reply with Quote
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 :

into Corpus.dbo.tbl_BasicInfos
select * from
'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 !

Premature Yak Congratulator

22847 Posts

Posted - 11/21/2005 :  01:04:14  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Declare @excelPath varchar(100)
Declare @sheetname varchar(100)
Declare @sql varchar(1000)
set @excelPath='File Path'
set @sheetname='SheetName'

Set @sql ='
Select * from 
''EXCEL 8.0;Database='+@excelpath+';HDR=NO'',
''SELECT * FROM ['+@sheetname+'$]'')'

Exec (@sql)


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000