Keyboard shortcut to automatically wrap selected text in IsNull([text], 0) in SSMS

前端 未结 2 1948
忘掉有多难
忘掉有多难 2021-01-22 07:42

Is there some way to have a shortcut in SQL Server Management Studio (SSMS) that when text is selected, it wraps that text in an IsNull() statement?

For example, I highl

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 08:20

    You can get this done using snippets. It's not exactly a simple shortcut, but a few keystrokes will get you there.

    First you need to create a snippet like this:

    
    
        
            
    ISNULL Inserts ISNULL function Luis Cazares SurroundsWith

    Save this as a .snippet file and save it on a folder destined for snippets. You could use the one set as default. To know which folder is your default or to add a different folder, go to the Code Snippets Manager in the Tools menu for SSMS.

    Once your snippet is on a registered location, select the code, press Ctrl+K,Ctrl+S and the snippets context menu will appear. You can traverse it by starting typing the folder and snippet name and pressing Enter or Right when getting there.

    It's probably not worth it for short snippets, but for larger ones it's amazing. I wrote a more detailed explanation in here.

提交回复
热议问题