Tabs or Spaces

  • Online - doesn't plug in to SQL Server Tools, but useful for a quick format of T-SQL:

    Instant SQL Formatter

    --Also worth noting that if someone used comments within the T-SQL, it could fail to format.

  • Peter Schott (3/19/2012)


    Online - doesn't plug in to SQL Server Tools, but useful for a quick format of T-SQL:

    Instant SQL Formatter

    --Also worth noting that if someone used comments within the T-SQL, it could fail to format.

    Thanks for the prompt reply. Comments shouldn't be a problem in this situation. Not sure whether to laugh or weep at this.

  • It's come in handy for me on several occasions. Embedded SQL seems to be the main use, but sometimes a copy/paste doesn't pick up the line formats or I'm reading off a SQL Trace where the formatting is lost. I have found some issues with the single-line comments (--). You'll need to break those out onto their own lines for the formatting to work properly if the line breaks are lost. Outside of that, it works well and I don't see how any parser would determine between comment and code if that's in line. 🙂

  • Rose Bud (3/19/2012)


    Peter Schott (3/19/2012)


    Online - doesn't plug in to SQL Server Tools, but useful for a quick format of T-SQL:

    Instant SQL Formatter

    --Also worth noting that if someone used comments within the T-SQL, it could fail to format.

    Thanks for the prompt reply. Comments shouldn't be a problem in this situation. Not sure whether to laugh or weep at this.

    Weep! Unless it's so darn obvious what it does.:-)

  • SQLRNNR (3/19/2012)


    Nadrek (3/18/2012)


    My answer to tabs vs. spaces, case convention, and pre vs post commas is always to let a computer do tedious, menial, purely rules based work - use a SQL beautifier/formatter. If someone else doesn't like your settings, they can use _their_ settings. None of that matters to the SQL parsing engine, so why should it matter to us?

    +1:-D

    Heh... -1. To do it right, IMHO, you should write code for humans, not for the computer, because humans have to maintain the code. If you wanted to write code for the computer, you'd be using raw machine language.

    I have a huge personal dislike for things like leading commas and the reasons why people think it's a good idea to use them but I'm not one to judge code based on such a personal preference. Seeing virtually any type of decent formatted code is a joy compared to some of the stuff I have seen on these forums and in real life. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • MarbryHardin (3/19/2012)


    Tabs, all the way.

    Saying that you want to use spaces because people will write improperly formatted code is a hack. Tabs have the same usefulness and purpose in writing SQL as they do in C#. The people that will use spaces where they should have tabs probably won't use either correctly (if at all), so why would you want to deliberately shoot yourself in the knee for them?

    Spaces are a cop out. Next thing you know you'll be recommending cursors because someone may someday work on the code that doesn't understand other constructs. 😉

    As Lynn said, that's really an apples/oranges comparison but I appreciate the passion.

    SQL Server very nicely works with tabs converted to spaces and comes in real handy when you open code that has different tabs stops set. I prefer mine to be set at 4, some go with the default of 8. Both settings play hell on your code if you need to quickly open something up with Notepad which has a default of 15.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • We are using Space instead of Tab. Reason: code looks perfect in any editor.

    To replace the tab with space, SSMS provides "Untabify Selected Lines" option. Only problem this option has is it is not replacing tab with space in comments. For that we can use Visual Studio editor - same option.

    Also we can insert space instead of tab by setting SSMS options.

    Thanks

  • I say pick a standard and stick to it. It doesn't matter which one, as long as everybody uses the same one.

  • I think the point about using non-default settings is the crucial one - I can persuade people to format code half decently but getting them to change default settings seems trickier, and space formatted layouts become unmaneageable without changing settings.

    We all use Notepad++ here if not using SSMS, which deals with tabs admirably. I'd recommend downloading it - now! - if you are still stuck using Notepad.

  • Jeff Moden (3/19/2012)


    Seeing virtually any type of decent formatted code is a joy ... 😀

    +1

    My coworkers laugh at me because before I'll even begin troubleshooting their code, I'll format it quickly so that I can see what I'm looking at. It would be some much easier if they picked any type of formatting, doesn't have to be the formatting I'm accustomed to.



    The opinions expressed herein are strictly personal and do not necessarily reflect the views or policies of my employer.

  • Rose Bud (3/19/2012)


    Can anyone recommend a free or very inexpensive SQL Beautifier/Formatter which works well with complex queries? One that integrated with SSMS 2008 would be ideal.

    I *love* SQL Prompt from RedGate, it's not terribly expensive and the Format SQL command has a two-keystroke shortcut (^K^Y). Does a bunch of other stuff too like enhancing intellisense. And it integrates into SSMS.

  • i prefer tabs to spaces.

    main reason is probably because i can highlight multiple rows and tab them across where as if i did that with the spacebar it would delete the rows.

    also because i think its easier to align rows with tabs.

  • davidandrews13 (3/20/2012)


    i prefer tabs to spaces.

    main reason is probably because i can highlight multiple rows and tab them across where as if i did that with the spacebar it would delete the rows.

    also because i think its easier to align rows with tabs.

    In SSMS, highlight those rows and hit tab to move across or shift+tab to move left... I use spaces all the time and have zero deletions.

  • Heh, anyone else agree that anything produced by the Query Designer is visually heinous?

    [font="Courier New"]Looking for a Deadlock Victim Support Group..[/font]
  • This was entertaining - kind of like 'The Crusades' in the middle ages ...

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 15 posts - 31 through 45 (of 49 total)

You must be logged in to reply to this topic. Login to reply