必须声明表变量

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

这篇关于必须声明表变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Query with t(n) and multiple cross joins(使用 t(n) 和多个交叉连接进行查询)
Unpacking a binary string with TSQL(使用 TSQL 解包二进制字符串)
Max rows in SQL table where PK is INT 32 when seed starts at max negative value?(当种子以最大负值开始时,SQL 表中的最大行数其中 PK 为 INT 32?)
Inner Join and Group By in SQL with out an aggregate function.(SQL 中的内部连接和分组依据,没有聚合函数.)
Add a default constraint to an existing field with values(向具有值的现有字段添加默认约束)
SQL remove from running total(SQL 从运行总数中删除)