What are the challenges you face when working across database platforms? Take the survey
Options

Alias added to computed column

a.higginsa.higgins Posts: 90 Bronze 2
edited January 16, 2017 1:27PM in SQL Prompt
Today I modified some code and added a computed column to a table variable:
DECLARE @TableVar TABLE
	(
		Col1 INT
	   ,Col2 AS Col1 * 1
	)

INSERT INTO @TableVar
	(
		Col1
	)
VALUES (1)

SELECT tv.Col1
FROM @TableVar tv

When I apply formatting to this code snip, it adds an alias to the computed column, as follows:
DECLARE @TableVar TABLE
	(
		Col1 INT
	   ,Col2 AS [@TableVar].Col1 * 1
	)

INSERT INTO @TableVar
	(
		Col1
	)
VALUES (1)

SELECT tv.Col1
FROM @TableVar tv

Before formatting, the query works fine: after formatting, the query breaks.

Can you modify SQL Prompt to avoid adding alias to computed column specifications?

Comments

Sign In or Register to comment.