Thursday, March 8, 2012

Code formatting for SQL2005 TSQL

Hi !
I have a monster case statement in TSL, autogenerated with some external
program I do not have access to.
The source file is about 4K in size, and the resulting source code probably
will have a few hunderd lines of code if formatted properly for reading.
Is there a feature in SQL 2005 management studio for code formatting ? BIDS
then ?
If not, a reccommendation for a tool for code formatting, preferably free,
would be greatly appreciated.
Regards,
Palli
"Pall Bjornsson" <palli@.kvos.is> wrote in message
news:ejv5S05nHHA.1388@.TK2MSFTNGP05.phx.gbl...
> Hi !
> I have a monster case statement in TSL, autogenerated with some external
> program I do not have access to.
> The source file is about 4K in size, and the resulting source code
> probably will have a few hunderd lines of code if formatted properly for
> reading.
> Is there a feature in SQL 2005 management studio for code formatting ?
> BIDS then ?
> If not, a reccommendation for a tool for code formatting, preferably free,
> would be greatly appreciated.
> Regards,
> Palli
Like this?
http://www.simple-talk.com/sql/sql-tools/the-simple-talk-sql-prettifier/
|||>
> Like this?
> http://www.simple-talk.com/sql/sql-tools/the-simple-talk-sql-prettifier/
>
Thanks for the link!
It does half the job, but not quite. It gets confused when 5 or 6 case
statement's END appear in a row!
Any other free options ?
Palli
|||"Pall Bjornsson" <palli@.kvos.is> wrote in message
news:ealOwM8nHHA.4424@.TK2MSFTNGP03.phx.gbl...
> Thanks for the link!
> It does half the job, but not quite. It gets confused when 5 or 6 case
> statement's END appear in a row!
> Any other free options ?
> Palli
If you report that as a possible bug to the author, I imagine he'll jump in
and try to fix it. I don't really know of any other free options myself. I
have heard about some old VB6 trick to access some undocumented feature of a
system DLL to format SQL/T-SQL Code. Not sure where the info is located for
this trick exactly, or if it would even work for SQL 2005, but you might be
able to Google something on it. The problem is that generally a custom code
prettifier for a language as complex as SQL/T-SQL would require you to
implement an LALR parser and a complete SQL/T-SQL grammar from scratch, or a
very deep (read: "slow") recursive-descent parser. For most people it's
probably just a lot easier to prettify their code by hand or just pay for a
pre-built package.
|||Try http://www.sqlinform.com/ and
http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm
TheSQLGuru
President
Indicium Resources, Inc.
"Pall Bjornsson" <palli@.kvos.is> wrote in message
news:ealOwM8nHHA.4424@.TK2MSFTNGP03.phx.gbl...
> Thanks for the link!
> It does half the job, but not quite. It gets confused when 5 or 6 case
> statement's END appear in a row!
> Any other free options ?
> Palli
>
|||Now that link is too cool I've heard of the GSP, but didn't realize
someone had set up a Web Service to use it.
"TheSQLGuru" <kgboles@.earthlink.net> wrote in message
news:OHbsgqYoHHA.1388@.TK2MSFTNGP05.phx.gbl...
> Try http://www.sqlinform.com/ and
> http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm
> --
> TheSQLGuru
> President
> Indicium Resources, Inc.
> "Pall Bjornsson" <palli@.kvos.is> wrote in message
> news:ealOwM8nHHA.4424@.TK2MSFTNGP03.phx.gbl...
>
|||> Try http://www.sqlinform.com/ and
> http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm
>
This is really cool... both of those tools. Thanks a lot.
Palli
|||"Pall Bjornsson" <palli@.kvos.is> wrote in message
news:uWen8lpoHHA.3460@.TK2MSFTNGP04.phx.gbl...
> This is really cool... both of those tools. Thanks a lot.
> Palli
BTW, Phil Factor (the author of the one I sent you) has updated his code.
He also has the source code for the T-SQL stored procedure available for
download. Not sure if it fixes the bug you pointed out, but it might.

No comments:

Post a Comment