必须声明表变量

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)