sql-server - 将表传递给存储过程会出现无效列错误
问题描述
我编写了一个存储过程(usp_Roll_UP),它将被其他过程调用。我收到以下错误消息。我将该数据复制到#temp 表并通过表中的一列进行查询。我使用#Temp 的原因。我需要删除在过程中处理的数据。
我收到以下错误消息:
消息 207,级别 16,状态 1,过程 usp_Roll_UP,第 38 行 [批处理开始行 235]
列名“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
解决方案
我认为你不能保持相同的名字。
SELECT * INTO #AllData FROM @AllData 我从上面的行更改为下面的修复了问题
从@AllData 中选择 * 到 #Temp
推荐阅读
- mysql - MySQL Workbench,如何修复“SELECT is not valid at this position for this server version”错误
- python - 带通配符的“全部规则”输入
- python - 是否有类似于法语 AFINN 的数据集(每个单词的分数在 -5 和 +5 之间,基于情绪)?
- mrtk - 将物品附在手上
- python-3.x - 当我尝试从 anaconda 启动 Spyder 时,出现与 PyQt5 相关的启动错误
- r - 如何在 geom_point 图中使用 geom_label 标记一个点,该点遵循后者的颜色渐变?
- android - rxjava 使用房间时遇到问题
- javascript - Wix React 本机导航选项卡按钮在导航回屏幕时超出范围
- assembly - Container VS HardBones Syscall 使用的差异 [Linux]
- javascript - firebase.database.ref 不是函数错误