当我在 Excel 中创建一个与 SQL 的连接时,该连接具有一个用于查找的临时表,并且我对 SQL 查询的参数进行了硬编码,一切都运行良好。当我将硬编码参数更改为?为了能够使用单元格中的动态参数,我在 Temp Table 上收到 Invalid Object Name 错误。任何帮助是极大的赞赏。
SET NOCOUNT ON
CREATE TABLE #ACTUALPENDCODESLIST
(ID INT IDENTITY(1,1) PRIMARY KEY,
PENDCODE CHAR(2),
PENDDESCRIPTION VARCHAR(255),
AREAOFOWNERSHIP VARCHAR(255),
PendQueue VARCHAR(255),
PendPriority INT)
INSERT INTO #ACTUALPENDCODESLIST VALUES ('02','PEND - PHYSICIAN/GROUP NOT CONTRACTED FOR RENAL CARE SERVICES','N/A','Not Applicable',999)
INSERT INTO #ACTUALPENDCODESLIST VALUES ('03','PEND - PROC DETAIL NOT FOUND ON FILE','Claims','MCLAIM/HCLAIM',267)
SELECT DISTINCT(SUBSTRING(ph.FREE_FORM_DATA, 16,2)) AS 'Pend Code',
apc.PENDDESCRIPTION AS 'Description',
COUNT(DISTINCT(ph.CLAIM_NBR)) AS 'Count'
FROM process_hist ph
INNER JOIN #ACTUALPENDCODESLIST apc
ON SUBSTRING(ph.FREE_FORM_DATA, 16,2) = apc.PENDCODE
WHERE ph.YMDTRANS BETWEEN ? AND ?
AND ph.OP_NBR NOT LIKE 'SYS%'
AND ph.OP_NBR NOT LIKE 'SMK%'
AND SUBSTRING(ph.FREE_FORM_DATA, 13,2) = 'EX'
AND SUBSTRING(ph.FREE_FORM_DATA, 16,2) IN (SELECT PENDCODE FROM #ACTUALPENDCODESLIST)
GROUP BY SUBSTRING(ph.FREE_FORM_DATA, 16,2), apc.PENDDESCRIPTION
ORDER BY [Count] DESC, [Pend Code]
DROP TABLE #ACTUALPENDCODESLIST```