Be careful with alias closure brackets in queries

As shown below, not closing alias brackets can cause SSMS column display readability issues and more importantly your query to not execute as expected.

--declare table
DECLARE @t TABLE (c1 varchar(10),c2 varchar(10));

--insert some data
INSERT INTO @t(c1,c2) VALUES ('one','two');
INSERT INTO @t(c1,c2) VALUES ('three','four');

--view data
 c1 AS [column1
,c2 AS [column2]
FROM @t;

If you send the results to text, you can observe what is occurring and c2 is not considered in the query.
The above was using the latest SSMS v17.0 version.

Leave a Reply