Sqlcmd formatting for better vizualization (part 2)

Goal

To keep when possible the same display as SSMS GUI has for the output of a SELECT statement.

My way of achieving it

By creating a SP that will generate a dynamic tsql for the select statement or by rewriting the select statement.

I haven’t come up with the SP yet but I created the code that will generate the dynamic tsql that we can run to format the output. The select must be simple more exactly the columns provided in the select statement otherwise it will break the code.  More than that, some type of columns and chars need more attention and when those are displayed, this might break the formatting also. As an example you can see first a result of select name,create_date,compatibility_level from sys.databases followed by a result of select name,create_date,owner_sid,compatibility_level from sys.databases which prove the formatting challenges if some of the columns contains some kind of chars.

sqlcmdoutput2

Nevertheless the code can be modified to deal with these situations and format them properly.

The code can be downloaded from here

Leave a Reply

Your email address will not be published. Required fields are marked *