Qualify Object Names bug with table variables

Provides intelligent code completion for SQL Server editors.

Moderators: Anu Deshpande, Aaron Law, David Priddle

Qualify Object Names bug with table variables

Postby sognibene » Sun Dec 01, 2013 10:19 pm

Consider the following code:

Code: Select all
DECLARE @MyTable TABLE (
   ID INT NOT NULL PRIMARY KEY,
   Name VARCHAR(200) NOT NULL,
   [Address] VARCHAR(200) NULL
);

INSERT INTO @MyTable
        ( ID, Name, Address )
VALUES  ( 1, -- ID - int
          'test', -- Name - varchar(200)
          '123 Main St.'  -- Address - varchar(200)
          )


SELECT  * FROM @MyTable WHERE ID = 1;


If you run "Qualify Object Names" on this code (SSMS 2012 SP1, SQL Prompt 6.1.0.101), it transforms the last line to say...

Code: Select all
SELECT  * FROM @MyTable WHERE @MyTable.ID = 1;


...which is invalid SQL.
sognibene
 
Posts: 7
Joined: Tue May 28, 2013 7:01 pm

Postby Aaron Law » Mon Dec 02, 2013 12:42 pm

Thank you for the detailed recreation steps! I think I have a fix and I've made a private build for you which you can download from here.

Note: the private build only had minimal testing so if you'd rather stay with 6.1.0.101 then a work around would be to give the variable an alias which prompt will then qualify the column with.
Aaron Law
 
Posts: 262
Joined: Fri Jun 28, 2013 10:56 am
Location: Red Gate Software


Return to SQL Prompt 6

Who is online

Users browsing this forum: No registered users and 0 guests

cron