Table of Contents
SQL Server Error: 137
Severity: 15
Event Logged or not: No
Description:
Must declare the scalar variable “%.*ls”.
Severity 15 Description:
Indicates syntax errors in the Transact-SQL command.
Identifying SQL Server Error Log File used by SQL Server Database Engine can be done by reading SQL Server Error Logs. DBA can execute the XP_READERRORLOG extended stored procedure to read the SQL Server Error Log and search for its location used by the instance of SQL Server.
USE master
Go
xp_readerrorlog 0, 1, N'Logging SQL Server messages in file', NULL, NULL, N'asc'
Go
When a variable is utilised in a SQL script without first defining it, this error occurs. Error 137 is returned by this example:
SET @varcol = 'Name'
select @varcol
The use of a variable declared outside the EXECUTE statement is one of the more sophisticated sources of this problem. For instance:
DECLARE @varcol nvarchar (20)
Go
SET @varcol= 'Name'
Go
EXECUTE ('SELECT @varcol FROM Customers')
Before using any variables in a SQL script elsewhere in the script, be sure they are defined.
Rewrite the procedure such that it does not refer to variables specified outside of it in the EXECUTE statement.
DECLARE @varcol nvarchar(20)
SET @varcol= 'Name'
EXECUTE ('SELECT ' + @varcol+ ' FROM Customers')
DECLARE @local variable is another option.
SQL Server Error: 137
Severity: 15
Event Logged or not: No
Description:
Must declare the scalar variable “%.*ls”.
Make sure that the syntax is correct.
Learn about SQL Server detecting logical consistency based issues and how to resolve them.
Learn about SQL Server error 1222 and how to resolve the lock request time out…
Discover the new features of Microsoft SQL Server 2022 and how they compare to previous…
SQL Server Error 1222 lock request time out period exceeded Lock request time out…
SQL Server Error : 427, Severity: 20. Could not load the definition for constraint ID…
SQL Server Error : 204, Severity: 20. Normalization error in node %ls.
This website uses cookies.