I have this query as part of a stored procedure, and this query as it is listed here works:
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=G:\KF\GBSData.xls;',
'SELECT * FROM [Sheet1$]')
SELECT * FROM [KWF_GBSData].[dbo].[tblKWF_WorkTable2]
WHERE invoiceNumber IN (
SELECT invoiceNumber
FROM [KWF_GBSData].[dbo].[tblKWF_WorkTable2]
WHERE stockNumberShipped LIKE 'CCCOMBO%'
)
I would like to change the 'SELECT * FROM [Sheet1$]'
to something a little more dynamic so that I can use a parameter for the Excel worksheet name rather than it always using Sheet1$. I would also like to use a parameter for the WHERE stockNumberShipped LIKE 'CCCOMBO%'
so that I can pass in the stockNumberShipped value. Simply put, I want to pass in the worksheet name and stock number via parameters.
I have tried this but it keeps giving syntax errors:
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=G:\KF\GBSData.xls;',
'SELECT * FROM [@pWorksheetName$]')
SELECT * FROM [KWF_GBSData].[dbo].[tblKWF_WorkTable2]
WHERE invoiceNumber IN (
SELECT invoiceNumber
FROM [KWF_GBSData].[dbo].[tblKWF_WorkTable2]
WHERE stockNumberShipped LIKE @pItemNumber%
)
I have also tried different variations on that, it just keeps giving syntax errors. So I am asking for hints & suggestions, if anyone can help.