ExcelGuyDude
Board Regular
- Joined
- Feb 4, 2015
- Messages
- 205
I'm using Excel 2010. I'm getting an error every time I try and pass a parameter straight through to my SQL query so I don't have to use VBA (very long SQL Code). I'm using an ODBC connection that I connected with the "From Microsoft Query" tool that's available. What I'm trying to do is use the question mark feature to replace the conditions I have currently set (W1 and 100000).
When running this code, everything works fine.
What I'd like the code to look like is this:
When I run try and run this query with the new changes, it gives me these 2 errors:
[Microsoft][ODBC SQL Server Driver]Invalid parameter number
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
I'm not sure if there's a setting I need to activate in Excel, or if this is not even possible to do with Temp tables within the SQL code.
Also, I know it's possible to put the SQL code inside of MS Access then do a pass-through query to Excel. I'm avoiding MS Access on purpose.
Thanks in advance for your help,
GuyDude
Code:
SET NOCOUNT ON
SELECT ib.Item#
, ib.AvailQty
INTO #InventoryTable
FROM ITEM_INVENTORY_BALANCES ib WITH(NOLOCK)
WHERE ib.Whse# = 'W1'
AND ib.AvailQty > 100000
SELECT *
FROM #InventoryTable
DROP TABLE #InventoryTable
When running this code, everything works fine.
What I'd like the code to look like is this:
Code:
SET NOCOUNT ON
SELECT ib.Item#
, ib.AvailQty
INTO #InventoryTable
FROM DATAWSQL.dbo.ITEM_INVENTORY_BALANCES ib WITH(NOLOCK)
WHERE ib.Whse# = ?
AND ib.AvailQty > ?
SELECT *
FROM #InventoryTable
DROP TABLE #InventoryTable
When I run try and run this query with the new changes, it gives me these 2 errors:
[Microsoft][ODBC SQL Server Driver]Invalid parameter number
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
I'm not sure if there's a setting I need to activate in Excel, or if this is not even possible to do with Temp tables within the SQL code.
Also, I know it's possible to put the SQL code inside of MS Access then do a pass-through query to Excel. I'm avoiding MS Access on purpose.
Thanks in advance for your help,
GuyDude