Blog Layout

SQL code snippets to save the ol joints

E.DIN Editor • May 11, 2020
As we type in SSMS all day long and type the same things over and over, and in case you did not know about the snippet mgr or know how to exploit it…
You can build a library of “Surround With” snippets to save you a BUNCH of keystrokes every day.  Below are the instructions along with an attached xml code sample.
  1. Save the attached to a folder, say: /snippets/
  2. Create a folder under snippets , say: /snippets/My Snippets/
  3. So now you have a .snippet file and a folder in: /snippets/
  4. Go to SSMS and hit: CTRL+K,CTRL+B (hold the CTRL key down and hit K, then B
  5. Click: ‘Add…’
  6. Find and select your “My Snippets” folder on your OS
  7. Back at the Code Snippets Manager, Click: ‘Import…’
  8. Navigate to your root /snippets/ folder and select the .snippet file that you downloaded from this email
  9. Select to add this file to your “My Snippets” container (check the box on the right) and click: Finish
  10. Now you are ready to execute the “Surround With” command you added…
  11. Either run the command to start off a query, OR, highlight a table name to query.  Hit: CTRL+K,S (hit K then S while holding down CTRL)
  12. Just use your arrow keys and the ENTER to find and select your new command within your “My Snippets” container so you don’t have to leave the keyboard
  13. Below was the result of me highlighting the fully qualified table name and executing the snippet

    SELECT_TOP.SNIPPET

     <?xml version="1.0" encoding="utf-8" ?>   
    
    <CodeSnippets  xmlns="https://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>SELECT_TOP_1000</Title>  
                            <Shortcut>t</Shortcut>  
    <Description>Snippet for SELECT TOP</Description>  
    <Author>Patrick Fitzgerald</Author>  
    <SnippetTypes>  
       <SnippetType>SurroundsWith</SnippetType>  
    </SnippetTypes>  
    </Header>  
    <Snippet>  
    <Declarations>  
                   <Literal>  
                   <ID>SELECTOP1000</ID>
                   <ToolTip>SELECT TOP 1000 From Selected Table</ToolTip>
                   <Default>SELECTOP1000</Default>
                   </Literal>  
    </Declarations>  
    <Code Language="SQL"><![CDATA[SELECT TOP 1000 * FROM $selected$$end$;]]>  
    </Code>  
    </Snippet>  
    </CodeSnippet>  
    </CodeSnippets>
    By E.DIN Editor 17 Nov, 2021
    Title: Base64 Encoding With Simple Salt (and decoding)
    By E.DIN Editor 17 Nov, 2021
    XPCMD_SHELL Move & Load Data from Directory
    By E.DIN Editor 17 Nov, 2021
    By E.DIN Editor 17 Nov, 2021
    By E.DIN Editor 01 Oct, 2020
     ***** My Valid Data Monitor **** XML OUT *** HTML EMAIL DELIVERY  *****IF OBJECT_ID('tempdb..#tCustomerID') IS NOT NULL DROP TABLE #tCustomerID    select distinct         mm.CustomerID  Into #tCustomerID    from myDatabase..myTable (nolock) mm     left join myDatabase.dbo.myOtherTable (nolock) mo  on mm.refID = mo.id     left join myDatabase.dbo.myOtherTableDetail (nolock) mod  on mo.id = mod.myOtherTableid         and mm.SearchValue = mod.SearchValue     where mm.refID is not null     and mm.quantity is not null      and mod.SearchValue is nullIF Exists (Select 1 From #tCustomerID)BEGIN DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)SET @xml = CAST(( SELECT [CustomerID] AS 'td' FROM #tCustomerID ORDER BY CustomerID FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))SET @body ='

    My Valid Data Monitor

    '    SET @body = @body + @xml +'
    CustomerID
    '--SELECT @body  exec msdb.dbo.sp_send_dbmail  @profile_name  = 'dbmailProfile' ,@recipients    = 'usergroup@mydomain.com' ,@subject       = 'My Valid Data Monitor' ,@body          = @body ,@body_format   = 'HTML'END
    By websitebuilder 20 Sep, 2020
    The new season is a great reason to make and keep resolutions. Whether it’s eating right or cleaning out the garage, here are some tips for making and keeping resolutions.
    By websitebuilder 20 Sep, 2020
    There are so many good reasons to communicate with site visitors. Tell them about sales and new products or update them with tips and information.
    By websitebuilder 20 Sep, 2020
    Write about something you know. If you don’t know much about a specific topic that will interest your readers, invite an expert to write about it.
    By tekp 15 Jul, 2020
    Turn Up! Not every microphone has the same base volume for transmitting your voice through your computer to whoever or whatever is on the other end of the exchange. Some microphones have a higher volume as compared to others, and some microphones have a volume that is so low that the person on the other […] The post How to Turn Up Mic Volume in Windows 10 – Appuals.com appeared first on TekPreacher.
    By E.DIN Editor 09 Jun, 2020
    '+@UNCPathAndLogTable+'
    More Posts
    Share by: