Poor Man’s T-SQL Formatter

When writing SQL or other programming languages, we all know how messy our code can get — mixing lower and upper case, placing commas in all the wrong place and many other issues all over the code.

It is good practice to have code that others can easily read. In other words, we want a clean code using a constant format — not like the code below.

/* written on 05/16/2017, by JDOE */
select distinct table01.field01, table01.field02
, table02.field03,table02.field04
from table01 inner join
table02
	on table01.field01 = table02.field01
	; -- messy code

This is where open-source plug-in Poor Man’s T-SQL Formatter (http://poorsql.com/) by Architect Shack (code available at GitHub) or other utilities come in handy when writing T-SQL. After running the utility, the code above is organized as shown below.

/* written on 05/16/2017, by JDOE */
SELECT DISTINCT table01.field01,
	table01.field02,
	table02.field03,
	table02.field04
FROM table01
INNER JOIN table02
	ON table01.field01 = table02.field01; -- clean code

I will start using Poor Man’s T-SQL Formatter (http://poorsql.com/) when teaching future T-SQL courses.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.