How can we help you today? How can we help you today?

Alias added to computed column

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?
a.higgins
0

Comments

4 comments

  • a.higgins
    For whatever it's worth, this appears to only apply to table variables: both temporary tables and true tables format without adding the alias.
    a.higgins
    0
  • Harry Frankish
    Hi a.higgins

    Thanks for reporting this issue. SQL Prompt shouldn't be qualifying column names for table variables.

    We'll hopefully have a fix for this soon. Until then you can stop SQL Prompt attempting to qualify column names by unchecking SQL Prompt > Options > Inserted code > Qualification > Qualify column names with table name.

    Cheers
    Harry
    Harry Frankish
    0
  • Harry Frankish
    Hi a.higgins

    I think this issue is fixed in this build: http://download.red-gate.com/EAP/SQLPro ... .0.236.exe

    Column names should no longer be qualified inside their own table variable's definition. Please let me know if it works for you.

    Cheers
    Harry
    Harry Frankish
    0
  • a.higgins
    Works great, thanks!
    a.higgins
    0

Add comment

Please sign in to leave a comment.