必须声明表变量
我在为数据导入编写一些 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
相关文章