declare @DB_in nvarchar(200), @Table_in nvarchar(50), @lcSQL nvarchar(200); SET @DB_in = N'C:\files\myTestDB.mdb' SET @Table_in = N'Table_1' SET @lcSQL = N'SELECT * FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'','''+@DB_in+''';''admin'';'''','+@Table_in+');' PRINT @lcSQL exec sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE; GO EXEC sp_executesql @lcSQL go exec sp_configure 'Ad Hoc Distributed Queries', 0; RECONFIGURE;The variable is declared, so why the error?? ... looking at the preview, the code segment does not interpret the single quotes correctly, but in SQL they are correct and the correct colors. :|
>SET @lcLKV='\\server\folder\any.accdb' > SET @lcSQL=N'INSERT INTO #LKV '+ > 'SELECT * > FROM OPENROWSET(''MSDASQL'', ''Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq='+@lcLKV+';Uid=;Pwd='', > ''SELECT * FROM [anytable] '') > ' > > --PRINT @lcSQL > > EXEC sp_executesql @lcSQL >>