Phil Factor's Phrenetic Phoughts

Simple-Talk columnist
The wilder shores of Transact SQL    Phil on Twitter   Phil on SQL Server Central  Phil on BOS

The Simple-Talk SQL Prettifier

Published Thursday, July 13, 2006 4:10 PM

(n.b. The prettifier is now on version 1.5 and is used by the editor and other contributors on this site to prepare code for publication. the link below has been updated to lead you to the latest version)

With this BLOG entry we launch the Simple-Talk SQL Prettifier. This takes SQL code and turns it into full-colour HTML code, primarily to make it easier to paste code into forum entries and blogs.

It is set up on a page here. Go there, paste in some SQL code (not too much please) and hit the 'Prettify' key. It will be hopefully transformed into full-colour HTML code. To get at it, click on the 'Source HTML' tag, and copy the HTML code out, and paste it into that erudite forum you were going to post to, or that nice page of documentation you keep promising to do.

I've been using it myself for quite a while now. I've found quite a few uses for it, as well as the obvious one of rendering code in browsers.

It is all written in one Stored Procedure

No cheating in the presentation layer, everything gets sent straight to a stored procedure for processing. It isn't as fast as doing it in a procedural language, but it sure is faster than doing it 'by hand'. Because it is in a stored procedure, it should be easier to integrate into any automated system you want to devise for 'documenting' your SQL Server code.

I've always been rather jealous of Lionel's splendid 3D maze game written in a stored procedure on this site. I believe that it is the most popular Blog entry. Rightly so, because I think that programmers should flex their muscles in their chosen language. I spit on anyone who says that Transact SQL is unsuitable for this sort of task so we shouldn't try. For heavens sake, that is why it is so much fun trying!

I wrote The SQL Prettifier because I needed it. Although I'm fond of it, I haven't the resources to refine it a great deal further. At the moment I write this there are SQL bits it will not parse (working…working…). If you find any bugs, or have comments and suggestions please let us know. If there is anyone who is tickled by the idea of the Prettifier, I'd be very pleased if they'd improve it and send us the results. The source is there to download and use.

Comments

 

Lon said:

I like it.  One of the things that aggrevates me about the Visual Studio automation is it wrapping more than one field on a line.  Each comma for a column should be then end of the line.  I also do not like how it reorders my where statements.  Sometimes it puts the date at the end when it needs to be the first thing searched on.  Also, Visual Studio will break apart OR statements making them harder to read and again less effecient.

Thanks,
Lon
July 17, 2006 1:05 PM
You need to sign in to comment on this blog


















<July 2006>
SuMoTuWeThFrSa
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
Niklaus Wirth: Geek of the Week
 It is difficult to begin to estimate the huge extent of the contribution that Niklaus Wirth has made to... Read more...

Building an Exchange Server 2007 environment
 Of course, changing a 32,000 mailbox system, based in 40 Exchange Servers, to a centralised 25,000... Read more...

Manage Stress Before it Kills You
 The key to a long career in IT is in learning how to cope adaptively with stress. Matt Simmons, like... Read more...

Expecting the Worst
 Optimists are often disappointed Read more...

To Boldly Ask IT for Development Work
 Phil has always been mystified by the way that, in Science-Fiction films, the crew of space-ships are... Read more...