Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit d3182e7

Browse files
authored
Merge pull request #4823 from MSDN-WhiteKnight/patch-1
Format queries as code blocks
2 parents 25114b4 + d30d2d1 commit d3182e7

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

docs/relational-databases/errors-events/mssqlserver-137-database-engine-error.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ ms.author: mathoma
2929
## Explanation
3030
This error occurs when a variable is used in a SQL script without first declaring the variable. The following example returns error 137 for both the SET and SELECT statements because **\@mycol** is not declared.
3131

32+
```sql
3233
SET @mycol = 'ContactName';
3334

34-
SELECT @mycol;
35+
SELECT @mycol;
36+
```
3537

3638
One of the more complicated causes of this error includes the use of a variable that is declared outside the EXECUTE statement. For example, the variable **\@mycol** specified in the SELECT statement is local to the SELECT statement; thus it is outside the EXECUTE statement.
3739

40+
```sql
3841
USE AdventureWorks2012;
3942

4043
GO
@@ -43,13 +46,15 @@ DECLARE @mycol nvarchar(20);
4346

4447
SET @mycol = 'Name';
4548

46-
EXECUTE ('SELECT @mycol FROM Production.Product;');
49+
EXECUTE ('SELECT @mycol FROM Production.Product;');
50+
```
4751

4852
## User Action
4953
Verify that any variables used in a SQL script are declared before being used elsewhere in the script.
5054

5155
Rewrite the script so that it does not reference variables in the EXECUTE statement that are declared outside of it. For example:
5256

57+
```sql
5358
USE AdventureWorks2012;
5459

5560
GO
@@ -58,7 +63,8 @@ DECLARE @mycol nvarchar(20) ;
5863

5964
SET @mycol = 'Name';
6065

61-
EXECUTE ('SELECT ' + @mycol + ' FROM Production.Product';) ;
66+
EXECUTE ('SELECT ' + @mycol + ' FROM Production.Product';) ;
67+
```
6268

6369
## See Also
6470
[EXECUTE (Transact-SQL)](~/t-sql/language-elements/execute-transact-sql.md)

docs/relational-databases/errors-events/mssqlserver-605-database-engine-error.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ If the 605 error is not transient, the problem is severe and must be corrected b
4848

4949
1. Identify the tables associated with the allocation units specified in the message by running the following query. Replace `allocation_unit_id` with the allocation units specified in the error message.
5050

51+
```sql
5152
USE`database_name`;
5253

5354
GO
@@ -67,6 +68,7 @@ If the 605 error is not transient, the problem is severe and must be corrected b
6768
ORDER BY au.allocation_unit_id;
6869

6970
GO
71+
```
7072

7173
2. Execute DBCC CHECKTABLE without a REPAIR clause on the table associated with the second allocation unit ID specified in the error message.
7274

0 commit comments

Comments
 (0)