Transact-SQL snippet indentation

Discussion Transact-SQL snippet indentation

  • Saturday, February 23, 2013 2:34 PM
     
     

    I have yet to find anything regarding indentation of inserted Transact-SQL snippets.

    So far, snippets seem to insert at the left margin with zero indentation.

    As a developer of snippets, are there any keywords I can add to the XML that will tell SSMS 2012 to continue the current level of Transact-SQL indentation?

    As a user of snippets, are there any SSMS settings that will tell SSMS 2012 to continue the current level of Transact-SQL indentation?

    Indentation is just as important to readability in Transact-SQL scripts as in compiled languages.

    I hope this is already supported in some (user and/or developer) form.  Otherwise I hope it will be implemented soon.


    Wayne Erfling (aka Cornan The Iowan)

All Replies

  • Saturday, February 23, 2013 7:16 PM
     
     
    Probably no help but SQLPrompt from Red Gate has what you need as one of its key features.  I am not aware of any Microsoft product that will do this.  http://www.red-gate.com/

    R, J

    • Edited by Crakdkorn Saturday, February 23, 2013 7:17 PM
    •  
  • Sunday, February 24, 2013 12:10 PM
     
     

    havent tried it with xml but you can try this sql formatter.

    http://www.dpriver.com/pp/sqlformat.htm


    http://joeydj.com/blogs

  • Sunday, February 24, 2013 8:43 PM
     
      Has Code

    I can't reproduce this.  In SQL 2012 (SP1) SSMS the tabs in this snippet are honoured:

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    	<CodeSnippet Format="1.0.0">
    		<Header>
    			<Title>Tab Test</Title>
    			<Description>Tab Test</Description>
    			<Author>wBob</Author>
    			<SnippetTypes>
    				<SnippetType>Expansion</SnippetType>
    			</SnippetTypes>
    		</Header>
    		<Snippet>
    			<Code Language="SQL">
    				<![CDATA[	x
    	y
    	z]]>
    			</Code>
    		</Snippet>
    	</CodeSnippet>
    </CodeSnippets>

    I just used an ordinary tab when creating it.
  • Sunday, February 24, 2013 11:14 PM
     
     

    This topic is NOT about SSMS "honoring" explicit TABs that I enter - it is about continuing the existing document indentation.

    I suspect that this ability has not been carried forward from Visual Studio into SSMS, just as the "<Shortcut..." tag doesn't seem to work with SSMS Intellisense.

    I've set up one of my SSMS snippets with the basic number of leading spaces for an UN-indented line, but when I use this (or other) snippets in an indented context I'll apparently need to manually indent the snippets after insertion.


    Wayne Erfling (aka Cornan The Iowan)

  • Sunday, March 10, 2013 9:26 AM
    Answerer
     
     

    This topic is NOT about SSMS "honoring" explicit TABs that I enter - it is about continuing the existing document indentation.

    I don't think there is such a functionality in SSMS.

    You can show tabs & spaces

    You can show/hide tabs: Edit --> Advanced --> View White Space


    Kalman Toth Database & OLAP Architect
    Paperback / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012