[英]Pass Table to a stored Procedure give an error with Invalid column
I have written a stored procedure (usp_Roll_UP) which will be called from other procedures. 我已经编写了一个存储过程(usp_Roll_UP),它将从其他过程中调用。 I get the below error message.
我收到以下错误消息。 I copy that data to a #temp table and Query by one of the columns on the table.
我将该数据复制到#temp表中,并通过表中的列之一进行查询。 The reason i am using #Temp.
我使用#Temp的原因。 I need to Delete the data as it is processed in the procedure.
我需要删除该过程中处理的数据。
I get the below error message: 我收到以下错误消息:
Msg 207, Level 16, State 1, Procedure usp_Roll_UP, Line 38 [Batch Start Line 235]
消息207,级别16,状态1,过程usp_Roll_UP,第38行[Batch Start Line 235]
Invalid column name 'T_Week'.无效的列名“ T_Week”。
CREATE TYPE [dbo].[Usr_defined_Table ] AS TABLE(
[T_Year] [int] NULL,
[T_Week] [int] NULL,
[Measure] [varchar](100) NULL,
[Amount] [numeric](16, 2) NULL
)
Create Procedure usp_Roll_UP
@AllData Usr_defined_Table READONLY
AS
BEGIN
SELECT * INTO #Temp FROM @AllData
SELECT * FROM @AllData WHERE [T_Week] =5 -- Works give the records
SELECT * FROM #Temp WHERE [T_Week] =5 -- give me an error with
--- More business logic here. as the records are processed, i need to delete ---the data from this #Temp
END
Thies means that in your session where you try to save yor sp by executing Create Procedure
there is already temp table called #Temp
and this table has no column called T_Week
. Thies表示在您尝试通过执行
Create Procedure
来保存您的sp的会话中,已经有一个名为#Temp
临时表,该表没有名为T_Week
列。
Just drop this table before you execute your create proc
. 在执行
create proc
之前,只需删除该表即可。
Your create proc
cannot pass the parse because there is already temp table with the same name but another structure. 您的
create proc
无法通过解析,因为已经有名称相同但结构不同的临时表。
I think you cannot keep the same name. 我认为您不能保持相同的名字。
SELECT * INTO #AllData FROM @AllData I changed from above line to below fixed the issue SELECT * INTO #AllData FROM @AllData我从上一行更改为下一行,解决了此问题
SELECT * INTO #Temp FROM @AllData 选择* INTO #Temp FROM @AllData
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.