A New Use Case for SQL Prompt – Shrinking Code

I work for Redgate and write about products. I’ve got a series of SQL Prompt posts here on little things I like. SQL Prompt might be my favorite tool.  SQL Prompt will be yours as well if you give it a try.

I thought this would work, but I wasn’t sure. I saw some code the other day like this:

DECLARE @char AS CHAR(1); SET @char = NULL; SELECT ISNULL(@char, 0); SELECT COALESCE(@char, 0); SET @char = E; SELECT ISNULL(@char, 0); SELECT COALESCE(@char, 0);

I dropped it into SSMS, and of course, I couldn’t read much of it. I did a quick CTRL+K, CTRL+Y and it looked like this:

DECLARE @char AS CHAR(1); SET @char = NULL; SELECT ISNULL(@char, 0); SELECT COALESCE(@char, 0); SET @char = E; SELECT ISNULL(@char, 0); SELECT COALESCE(@char, 0);

Yeah, SQL Prompt. In addition to reformatting as I prefer, it removed the extra whitespace.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.