i am trying to pass a variable into an Openrowset - i have seen its not possible this way but not sure what the solution will be.
I need to do it as i have multiple files in need to pull data in from, my incorrect code is below:
DECLARE @XFILENAME AS VARCHAR(50)
DECLARE CUR_UPDATE SCROLL CURSOR FOR
SELECT PATH FROM TBL_FILENAME
OPEN CUR_UPDATE
--LOOP THROUGH RETRIEVED FILES --
FETCH NEXT FROM CUR_UPDATE
INTO
@XFILENAME
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT * INTO DBO.TEMP_NEWLEADIMPORT
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;HDR=YES;Database='+ @XFILENAME +'',
'SELECT * FROM [NewLeads$]')
FETCH NEXT FROM CUR_UPDATE
INTO
@XFILENAME
END
CLOSE CUR_UPDATE
DEALLOCATE CUR_UPDATE
I get the error 'Incorrect Syntax near +' as i assume the OPENROWSET is not expecting the variable.
I need to do it as i have multiple files in need to pull data in from, my incorrect code is below:
DECLARE @XFILENAME AS VARCHAR(50)
DECLARE CUR_UPDATE SCROLL CURSOR FOR
SELECT PATH FROM TBL_FILENAME
OPEN CUR_UPDATE
--LOOP THROUGH RETRIEVED FILES --
FETCH NEXT FROM CUR_UPDATE
INTO
@XFILENAME
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT * INTO DBO.TEMP_NEWLEADIMPORT
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;HDR=YES;Database='+ @XFILENAME +'',
'SELECT * FROM [NewLeads$]')
FETCH NEXT FROM CUR_UPDATE
INTO
@XFILENAME
END
CLOSE CUR_UPDATE
DEALLOCATE CUR_UPDATE
I get the error 'Incorrect Syntax near +' as i assume the OPENROWSET is not expecting the variable.