Create your own snippets of SQL code, and insert them into your queries
Part one of a four-part series of blogs

With SQL Server 2012 came the power not just to use pre-defined code snippets, but also to create your own - this blog explains how.

  1. Creating your own snippets of SQL (this blog)
  2. Three examples of the use of snippets
  3. Creating custom snippets using Snippets Generator
  4. Importing SQL Snippets into Management Studio

Posted by Andy Brown on 23 November 2017

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Creating your own snippets of SQL

I've blogged before about creating code snippets in SQL, but I never realised how easy - or how useful - it was to create your own snippets.  Before I go any further, credit where it's due:

What Notes
Original idea Thanks to Sam for doing the research for this, and for sending me an email detailing how to create your own snippets.  All I've done is to turn this into a blog!
Snippet generator I've used the excellent snippet generator from SQLArtBits, who are a community of SQL developers.

Any mistakes which follow are all mine!  I've divided this blog up into the following parts:

So let's get started! 

One word of warning: snippets were introduced in SQL Server 2012.  So if you're using SQL Server 2008 R2 or earlier, it's time, alas, to find some different lunchtime reading matter.

This blog has 0 threads Add post