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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Read Excel with Path trhu Parameters

Author  Topic 

load1982
Starting Member

3 Posts

Posted - 2010-02-02 : 09:07:40
Hi hope you can help me...

im trying to create a SP, to read an Excel file, but sending the Path thru the Paramters something like this:

create procedure getFileInfo(@Path nvarchar(254))
as
Select *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=' + @Path + ;HDR=No',
'SELECT * FROM [Seat Schedule$]') as Excel


but is giving me an error message

Msg 170, Level 15, State 1, Procedure getFileInfo, Line 4
Line 4: Incorrect syntax near '+'.

there any way to do this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-02 : 09:09:08
You need to use dynamic SQL
Read it here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-02-02 : 09:14:17
And just as an fyi, the reason for this particular error, outside of being the wrong format, was also because you missed a ' after you 2nd + sign.
Go to Top of Page

load1982
Starting Member

3 Posts

Posted - 2010-02-02 : 09:18:57
I really appreciate both comments, and thank you Madhivanan, im trying your solution right now
Go to Top of Page
   

- Advertisement -