I want to execute this query. Because only OPENROWSET don't work with variable :
EXEC
(
'
Insert into Table1
SELECT *
From OPENROWSET(MICROSOFT.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\Users\AA\Desktop\Table1.xlsx',
'SELECT *
FROM [Sheet1$] ) '
)
For insert in a table on SQL Server 2008 with a variable SQL. My objectif is to make the filepath dynamic like database='+@FilePath+'
Finally using this code in ado.Net in openFiledialog control
But it doesn't work I get a syntax error
I have solved but without insert query I think the same thing with insert always escape the quotes like that
EXEC
(
'SELECT *
From OPENROWSET(''MICROSOFT.ACE.OLEDB.12.0'',
''Excel 12.0;Database=C:\Users\AA\Desktop\Table1.xlsx'',
''SELECT *
FROM [Sheet1$]'') T
')
and with FilePath :
Declare
@FilePath nvarchar(50)
SET @FilePath='C:\Users\AA\Desktop\Table1.xlsx'
EXEC
(
'SELECT *
From OPENROWSET(''MICROSOFT.ACE.OLEDB.12.0'',
''Excel 12.0;Database='+@FilePath+''',
''SELECT *
FROM [Sheet1$]'') T
')