必须声明表变量

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

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

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

相关文档推荐

SQL query to group by day(按天分组的 SQL 查询)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
sql group by versus distinct(sql group by 与不同)
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
Count number of records returned by group by(统计分组返回的记录数)
SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)