I am wondering why the following doesn't work:
INSERT INTO @Data2 (FileName,Field)
SELECT @FileName as FileName, * FROM OPENROWSET(BULK '\\serverpath\' + @FileName , SINGLE_CLOB) AS Contents
I tried also the second approach but with this one I get the error message that the variable isn't declared:
declare @path nvarchar(255) = 'SELECT @FileName as FileName, * FROM OPENROWSET(BULK ''\\serverpath\' + @FileName + ''', SINGLE_CLOB) AS Contents'
INSERT INTO @Data2 (FileName,Field)
EXEC(@path)
Can somebody help? Thanks