MSSQLSERVER_137MSSQLSERVER_137
Aplica-se a:Applies to: SQL ServerSQL Server (todas as versões compatíveis)
SQL ServerSQL Server (all supported versions)
SQL ServerSQL Server (todas as versões compatíveis)
SQL ServerSQL Server (all supported versions)
DetalhesDetails
AtributoAttribute | ValorValue |
---|---|
Nome do ProdutoProduct Name | SQL ServerSQL Server |
ID do eventoEvent ID | 137137 |
Origem do EventoEvent Source | MSSQLSERVERMSSQLSERVER |
ComponenteComponent | SQLEngineSQLEngine |
Nome simbólicoSymbolic Name | P_SCALAR_VAR_NOTFOUNDP_SCALAR_VAR_NOTFOUND |
Texto da mensagemMessage Text | É necessário declarar a variável escalar "%.*ls".Must declare the scalar variable "%.*ls". |
ExplicaçãoExplanation
Esse erro ocorre quando uma variável é usada em um script SQL sem primeiro declarar a variável.This error occurs when a variable is used in a SQL script without first declaring the variable. O exemplo a seguir retorna o erro 137 para as instruções SET e SELECT porque @mycol não é declarada.The following example returns error 137 for both the SET and SELECT statements because @mycol is not declared.
SET @mycol = 'ContactName';
SELECT @mycol;
Uma das causas mais complexas desse erro inclui o uso de uma variável que é declarada fora da instrução EXECUTE.One of the more complicated causes of this error includes the use of a variable that is declared outside the EXECUTE statement. Por exemplo, a variável @mycol especificada na instrução SELECT é local na instrução SELECT, por isso está fora da instrução EXECUTE.For example, the variable @mycol specified in the SELECT statement is local to the SELECT statement; thus it is outside the EXECUTE statement.
USE AdventureWorks2012;
GO
DECLARE @mycol nvarchar(20);
SET @mycol = 'Name';
EXECUTE ('SELECT @mycol FROM Production.Product;');
Ação do usuárioUser Action
Verifique se alguma das variáveis usadas em um script SQL foi declarada antes de ser usada em outro lugar no script.Verify that any variables used in a SQL script are declared before being used elsewhere in the script.
Reescreva o script de modo que ele não faça referência a variáveis na instrução EXECUTE que estejam declaradas fora dela.Rewrite the script so that it does not reference variables in the EXECUTE statement that are declared outside of it. Por exemplo:For example:
USE AdventureWorks2012;
GO
DECLARE @mycol nvarchar(20) ;
SET @mycol = 'Name';
EXECUTE ('SELECT ' + @mycol + ' FROM Production.Product';) ;
Consulte TambémSee Also
EXECUTE (Transact-SQL)EXECUTE (Transact-SQL)
Instruções SET (Transact-SQL)SET Statements (Transact-SQL)
DECLARE @local_variable (Transact-SQL)DECLARE @local_variable (Transact-SQL)