Click here to monitor SSC

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
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. David Wesley... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across, and start getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...