Must declare the table variable(必须声明表变量)
问题描述
我在为数据导入编写一些 SQL 语句时遇到错误.
I come across an error while writing some SQL statements for data imports.
由于我在做数据端口,我需要声明一些临时表变量.
As I am doing data port, I need to declare some temporary table variables.
我在文件的开头声明了一个表变量,并对表变量执行了一些操作(while 循环、插入和更新).稍后在另一个 while 循环中的脚本中间,如果我访问此表变量,脚本解析给出以下错误
I declared a table variable at the beginning of the file and performed some manipulations (while loops, insertions and updates) on the table variable. Later in the middle of the scripts in another while loop if I access this table variable the script parsing giving below error
必须声明表变量@temptable
Must declare the table variable @temptable
感谢您的帮助.
推荐答案
如果先前声明的变量在执行的 SQL 代码块中不再可用,则很可能是调用了 GO 语句.
If a previously declared Variable is no longer available in a block of executed SQL Code, it is likely that a GO statement has been called.
根据 MSDN,局部变量的范围是声明它的批次.".
As per MSDN, "The scope of a local variable is the batch in which it is declared.".
Go 语句向 SQL Server 实用程序发出一批 Transact-SQL 语句结束的信号."
A Go Statement "Signals the end of a batch of Transact-SQL statements to the SQL Server utilities."
建议仔细检查您的 SQL 代码是否有任何错误的 GO 语句.
It is recommended to double check your SQL code for any errant GO statements.
参考文献:
声明@local_variable (Transact-SQL)http://msdn.microsoft.com/en-us/library/ms188927.aspx
DECLARE @local_variable (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms188927.aspx
GO (Transact-SQL)http://msdn.microsoft.com/en-us/library/ms188037.aspx
GO (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms188037.aspx
这篇关于必须声明表变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:必须声明表变量
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
