Phil Factor's Phrenetic Phoughts

Simple-Talk columnist
The wilder shores of Transact SQL

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
Ziggurats, Batman and the Town Crier
 We asked Brian for a description of the Help System for the software he's working on and ends up... Read more...

The Future of NET Reflector
 Simple Talk asked freelance writer Bob Cramblitt to sit down with the two people behind the agreement... Read more...

Software Tool Design: Remote User Testing
 If you are developing a software product, you'll know that the sooner you can get feedback from the... Read more...

SQL Toolbelt 2008: Predominantly an Engineering Task
 The conversion of the Red-Gate tools to be compatible with SQL Server 2008 might not seem, on first... Read more...

Andrew Tanenbaum: Geek of the Week
 Andrew Tanenbaum has had an immense influence on the way that operating systems are designed. He... Read more...