我想将 excel 的动态 URL 传递给“OPENROWSET”。
注意 - 我将返回的 excel 文件结果传递给光标。我想将文件路径传递给“@excelpath”,我尝试了很多方法,但它给出了语法错误。
ALTER procedure [dbo].[import_excel]
(
@excelpath as nvarchar(max)
)
as
begin
set nocount on
DECLARE insert_cursor CURSOR FOR
select * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\memberdata.xlsx', [Sheet1$])
OPEN insert_cursor;
FETCH NEXT FROM insert_cursor
INTO @id_number, @memberName
WHILE @@FETCH_STATUS = 0
BEGIN
-- body of cursor
FETCH NEXT FROM insert_cursor
INTO @id_number, @memberName
END
CLOSE insert_cursor;
DEALLOCATE insert_cursor;
END