(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.