Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 SQL Indenter

Author  Topic 

bba
Starting Member

3 Posts

Posted - 2003-05-23 : 13:55:48
Hi All,

Is there any freeware tool/utility available to indent/format the stored procedures. I have quite a few SPs developed by the previous developers that are not indented. I used sp_helptext to retrieve the source code for some SPs. SQL server does not indent them either.

Any help is greatly appreciated.

Regards
BBA

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-05-24 : 16:03:54
There's this neat feature available on most computer keyboards, called the TAB key. It does an excellent job of indenting.

I don't want to sound rude or anything, but indenting won't turn an incomprehensible procedure into a comprehensible one; you either understand what it does or you don't. If you don't, the best way to understand what it does is to go through it line-by-line and indent it yourself.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-05-24 : 20:43:36
>> but indenting won't turn an incomprehensible procedure into a comprehensible one.
Disagree - it can but only if it's incomprehensible due to formatting.

I also discovered that you can indent blocks by highlighting the block and hitting the tab key.
Not sure when but an embarrassingly long time after the feature must have been included.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2003-05-25 : 06:27:59
I'm pretty sure that was an addition to the client tools for SQL Server 2000. I take it you know that shift-tab unindents in the same way?


Go to Top of Page

dsdeming

479 Posts

Posted - 2003-05-27 : 08:00:18
quote:
I take it you know that shift-tab unindents in the same way?



Oops! I've been using block indent for a long time now and for just as long I've been grumbling about the lack of a block un-indent. Thanks, Arnold.

Go to Top of Page

bba
Starting Member

3 Posts

Posted - 2003-05-29 : 15:40:49
Thanks for your inputs. Actually, my boss has asked me to write a tool to do it , so other departments/locations can also reuse it. I thought if something already exists, I need not write it.

Any help is greatly appreciated.

--bba

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-05-30 : 07:22:56
quote:

...but indenting won't turn an incomprehensible procedure into a comprehensible one...



CREATE TABLE #n (n int PRIMARY KEY) INSERT #n
SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
UNION SELECT 5 SELECT CASE WHEN o=a THEN 'DK' WHEN o=b
THEN 'EN' WHEN o =c THEN 'DE' WHEN o=d THEN
'NO'ELSE'SE' END yak FROM (SELECT a.n a ,b.n b,c.n
c,d.n d,15 -a.n-b.n -c.n-d. n e,e.n f,f. n g,g.n h,
h.n i,15 -e.n-f.n-g.n-h.n j,i .n k,j.n l ,k.n m,l.n
n,15-i. n-j.n-k.n-l.n o,m.n p,n.n q,o.n r, p.n s,15
-m.n-n.n -o.n-p.n t,q.n u, r.n v,s. n w,t. n x,15
-q.n-r.n -s.n-t.n y FROM #n a,#n b,#n c, #n d,#n
e,#n f, #n g,#n h, #n i,#n j,#n k, #n l,#n
m,#n n, #n o,#n p,#n q, #n r,#n s,#n t) z WHERE
NOT(b=a OR c IN (a,b)OR d IN(a, b,c))AND NOT(g=

f OR h IN(f,g)OR i IN(f,g,h))AND NOT(l=k OR m IN(k,l)OR n IN(k,l,m))AND NOT(q
=p OR r IN(q,p)OR s IN(q,p,r))AND NOT(v=u OR w IN(u,v)OR x IN(u,v,w))AND q=g
AND x=k AND j=w AND r=3 AND d=1 AND v=p AND 1=ABS(u-l)AND g=i-1 AND 1=ABS(n-w)
AND c=y AND 1=ABS(d-f)AND e=m AND 1=ABS(t-u)AND a=s AND b=h DROP TABLE #n

 


Jay White
{0}
Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2003-05-30 : 07:30:25
LOL... That was nice! Reminds me of competition we had in school, where we were supposed to write the most unreadable C++ program...

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2003-05-30 : 07:41:40
Unreadable? Ok, they're ugly letters -- with long keywords and no macro language it was never going to look great -- but it's perfectly readable to me.


Edited by - Arnold Fribble on 05/30/2003 07:44:30
Go to Top of Page

dtecmeister
Starting Member

5 Posts

Posted - 2010-05-13 : 22:23:36
This is a bit late, but I ran into the same issues and created a fast SQL indenter that works on .cs files as well and comments where end blocks are not already commented in addition to the indentation formating. It's available for free and is here:
[url]http://www.softfrontiers.com/Downloads/ReIndenter.shtml[/url]

Thanks and enjoy!
Jeff Doak
Go to Top of Page
   

- Advertisement -