I have a SQL query via a MS Query connection into Excel that includes a temporary table.
Code:
CREATE TABLE #PV (ProductID varchar(255), Price int);
INSERT INTO #PV(ProductID, Price)
SELECT DISTINCT
PLR.ProductID, MAX(PLR.normal_price)
FROM
dbo.t_price_lists_r AS PLR
WHERE
PLR.price_list = 1115
GROUP BY
PLR.ProductID
SELECT P.ProductID, P.Price
FROM #PV AS P
BEGIN DROP TABLE #PV END
The code works fine in SSMS and returns the correct results, but I get three distinct errors when running it in Excel/MS Query, as follows:
Invalid column name 'ProductId'
Deferred prepare could not be completed
Statement(s) could not be prepared
I run SQL queries via Excel on a daily basis without incident, usually.
Many thanks in advance!