使用临时表和参数时excel对象名无效

ndh0cuux  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(350)

当我在excel中创建一个到sql的连接,其中有一个临时表用于查找,并且我硬编码sql查询的参数时,一切都正常运行。当我把硬编码参数改成?为了能够使用单元格中的动态参数,我在temp表中得到了一个无效的对象名错误。非常感谢您的帮助。

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```

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题