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
SELECT 
 c1 AS [column1
,c2 AS [column2]
FROM @t;

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

Leave a Reply