2

我的函数中有三个单独的表变量,其中 1 个没有给我任何错误,另外两个是,我没有发现它们之间有任何不同的语法,但也许我需要更多的咖啡因。

我收到的错误是

必须声明标量变量“@DispoTable”。

DECLARE @CIDdisp INT

DECLARE @DispoTable TABLE 
(
    CaseID INT,
    Code INT,
    Description VARCHAR(150)
)
--Gather Data From filter
SELECT @CIDdisp = CaseID, @Code = Code, @Description = Description
FROM fnRecidFilter3(@CaseID,01,01)
-- Insert into Temp table
INSERT INTO @DispoTable (CaseID, Code, Description)
VALUES (@CIDdisp, @Code, @Description)
-- Merge the Temp Table with RecidReport Table
INSERT INTO RecidReport(Code, Description)
SELECT Code, Description 
FROM @DispoTable
WHERE (@DispoTable.CaseID) = CaseID

有什么我想念的吗?

4

1 回答 1

4

你不能说:

WHERE (@DispoTable.CaseID) = CaseID

相反,您需要使用别名:

FROM @DispoTable AS d
WHERE d.CaseID = CaseID

但无论如何,这个条款毫无意义。您的意思是在这里使用变量吗?也许:

FROM @DispoTable AS d
WHERE d.CaseID = @CIDdisp

?

于 2012-07-03T15:41:00.390 回答