• I've seen that Prompt handles snippets in a wonderful way. I know that templates have been available for a long time, but I'm not sure if you could create custom templates and not only the "create new object" that came included.

    Of course, a code used over and over could be saved as a script, but when the code is usually part of something bigger, then a snippet could be a better option. For example, I made the following for a cteTally which can be inserted by Ctrl+K, Ctrl+X and a few other keystrokes.

    <?xml version="1.0" encoding="utf-8" ?>

    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

    <_locDefinition xmlns="urn:locstudio">

    <_locDefault _loc="locNone" />

    <_locTag _loc="locData">Title</_locTag>

    <_locTag _loc="locData">Description</_locTag>

    <_locTag _loc="locData">Author</_locTag>

    <_locTag _loc="locData">ToolTip</_locTag>

    <_locTag _loc="locData">Default</_locTag>

    </_locDefinition>

    <CodeSnippet Format="1.0.0">

    <Header>

    <Title>Tally CTE</Title>

    <Shortcut></Shortcut>

    <Description>Creates a cteTally</Description>

    <Author>Luis Cazares</Author>

    <SnippetTypes>

    <SnippetType>Expansion</SnippetType>

    </SnippetTypes>

    </Header>

    <Snippet>

    <Declarations>

    <Literal>

    <ID>cteTally</ID>

    <ToolTip>Code to create a cteTally</ToolTip>

    <Default>cteTally</Default>

    </Literal>

    </Declarations>

    <Code Language="SQL"><![CDATA[WITH

    E(n) AS(

    SELECT n FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(n)

    ),

    E2(n) AS(

    SELECT a.n FROM E a, E b

    ),

    E4(n) AS(

    SELECT a.n FROM E2 a, E2 b

    ),

    cteTally(n) AS(

    SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) n

    FROM E4

    )

    SELECT n

    FROM cteTally

    ]]>

    </Code>

    </Snippet>

    </CodeSnippet>

    </CodeSnippets>

    Or the following that would help me to create a concatenated string from a query. This one is called by Ctrl+K, Ctrl+S as this surround the selected text.

    <?xml version="1.0" encoding="utf-8" ?>

    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

    <_locDefinition xmlns="urn:locstudio">

    <_locDefault _loc="locNone" />

    <_locTag _loc="locData">Title</_locTag>

    <_locTag _loc="locData">Description</_locTag>

    <_locTag _loc="locData">Author</_locTag>

    <_locTag _loc="locData">ToolTip</_locTag>

    <_locTag _loc="locData">Default</_locTag>

    </_locDefinition>

    <CodeSnippet Format="1.0.0">

    <Header>

    <Title>FOR XML PATH</Title>

    <Shortcut></Shortcut>

    <Description>Creates a Concatenated list</Description>

    <Author>Luis Cazares</Author>

    <SnippetTypes>

    <SnippetType>SurroundsWith</SnippetType>

    </SnippetTypes>

    </Header>

    <Snippet>

    <Declarations>

    <Literal>

    <ID>FORXMLPATH</ID>

    <ToolTip>Code to create a Concatenated list</ToolTip>

    <Default>Concatenated list</Default>

    </Literal>

    </Declarations>

    <Code Language="SQL"><![CDATA[SELECT STUFF(( $end$$selected$

    FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 1, '')

    ]]>

    </Code>

    </Snippet>

    </CodeSnippet>

    </CodeSnippets>

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2