T-SQL 复制表变量
我正在尝试复制表变量:
DECLARE @lt_Sections TABLE
(
teamId SMALLINT NOT NULL
)
DECLARE @lt_tempSections TABLE
(
teamId SMALLINT NOT NULL
)
-- populate some values in @lt_Sections
-- take a copy of @lt_Sections
SET @lt_tempSections = @lt_Sections
这给了我一个错误:
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@lt_Sections".
我做错了什么?
谢谢, 标记
I'm trying to make a copy of a table variable:
DECLARE @lt_Sections TABLE
(
teamId SMALLINT NOT NULL
)
DECLARE @lt_tempSections TABLE
(
teamId SMALLINT NOT NULL
)
-- populate some values in @lt_Sections
-- take a copy of @lt_Sections
SET @lt_tempSections = @lt_Sections
This is giving me an error:
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@lt_Sections".
What have I done wrong??
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Set(或 select)只能应用于标量变量,不能应用于表变量。
您应该使用插入而不是设置值
Set (or select) can be applied only to a scalar variable not a Table variable.
Instead of setting values you should use Insert
您不能像这样复制表变量(将它们更多地视为真实/临时表)。
你需要:
You can't copy table variables like this (think of them more as you would a real/temporary table).
You'd need to: