SA0235 : Consider using the AS keyword to specify a column alias instead of the column_alias = expression syntax

The topic describes the SA0235 analysis rule.

Message

Consider using the AS keyword to specify a column alias instead of the column_alias = expression syntax

Description

This rule checks T-SQL script for use of column_alias = expression syntax.

While the assignment operator syntax is legal, the AS keyword syntax is recommended and is SQL ANSI standard.

How to fix

Use `expression as column_alias` syntax instead of the `column_alias = expression` syntax.

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Effort To Fix
2 minutes per issue.
Categories

Design Rules, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1-- OK
 2SELECT     au_id+au_id AS alias_for_col
 3FROM       dbo.authors
 4
 5-- OK
 6SELECT     au_id+au_id AS [alias_for_col]
 7FROM       dbo.authors
 8
 9-- OK
10SELECT     au_id+au_id AS "alias_for_col"
11FROM       dbo.authors
12
13-- OK
14SELECT     au_id+au_id AS 'alias_for_col'
15FROM       dbo.authors
16
17-- OK
18SELECT     column_alias=expression
19FROM       dbo.authors
20
21-- column_alias = expression syntax is used here, but ignored, because all rules at the violation line are suppressed.
22SELECT     alias_for_col=au_id+au_id, au_id --IGNORE:*(LINE)
23FROM       dbo.authors
24
25
26-- Deprecated alias syntax is used here. Reported by SA0008
27SELECT     'alias_for_col'=au_id+au_id
28FROM       dbo.authors
29
30DECLARE @variable int
31SELECT @variable = 1

Analysis Results
  Message Line Column
1 SA0235 : Consider using the AS keyword to specify a column alias instead of the column_alias = expression syntax. 18 23
See Also

Other Resources