I have written a stored procedure (usp_Roll_UP) which will be called from other procedures. I get the below error message. I copy that data to a #temp table and Query by one of the columns on the table. The reason i am using #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]
Invalid column name '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
.
Just drop this table before you execute your create proc
.
Your create proc
cannot pass the parse because there is already temp table with the same name but another structure.
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 #Temp FROM @AllData
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.