Вы также можете использовать Inner Join, EXISTS
вместо IN.Пожалуйста, обратитесь запрос EXISTS:
SELECT
vbs.SKUID, SKUName, SUM(vbs.Quantity) AS Qty
FROM
BatchStocks AS vbs
WHERE
EXISTS ( select 1 from #TEMPTABLE t on t.SKUID = vbs.SKUID)
AND vbs.StoreID IN (%q)
AND vbs.StockType = %n
GROUP BY
vbs.SKUID, vbs.SKUName
Пожалуйста, обратитесь ниже запрос для INNER JOIN:
SELECT
vbs.SKUID, SKUName, SUM(vbs.Quantity) AS Qty
FROM
BatchStocks AS vbs
INNER JOIN #TEMPTABLE t on t.SKUID = vbs.SKUID
WHERE vbs.StoreID IN (%q)
AND vbs.StockType = %n
GROUP BY
vbs.SKUID, vbs.SKUName