September 1, 2015 at 8:11 am
I'm not sure if this is still useful and works the same for 2014 and 2016. I've created a few for myself on 2012 and seem like a useful tool. I couldn't find any article about this and only found this forum post http://www.sqlservercentral.com/Forums/Topic1465260-2799-1.aspx
Would it be a good article or would it be irrelevant for the majority?
September 2, 2015 at 8:33 am
I'm not quite sure what you mean by this, Luis. When I think of snippets, I'm thinking of code I reuse over and over, but generally I just save the code to my Management Studio solution and the open it / alter as needed.
September 2, 2015 at 9:20 am
I use snippets in Prompt.
They've been in SSMS as Templates for a long time. You can drag/drop them into query windows. CTRL+Shift+M for parameters
September 2, 2015 at 10:04 am
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>
February 9, 2016 at 6:03 pm
bump
February 10, 2016 at 11:51 am
Steve Jones - SSC Editor (2/9/2016)
bump
Does this means that an article on this could be interesting?
February 16, 2016 at 3:10 pm
Luis Cazares (2/10/2016)
Steve Jones - SSC Editor (2/9/2016)
bumpDoes this means that an article on this could be interesting?
yes
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply