Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 highlight the text below:

My_column_name

and when I click the keyboard shortcut, what was highlighted turns into:

IsNull(My_column_name, 0)

I am using SSMS v17.4

like image 334
David Maddox Avatar asked Nov 18 '25 09:11

David Maddox


1 Answers

I may have found a way. In the C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\SQL\Snippets\1033\Function directory (adjust accordingly for your installation), I copied the Begin End.snippet file, named the copy IsNull.snippet, and modified the new file. I changed:

BEGIN

$selected$ $end$

END

To:

IsNull($selected$ $end$, 0)

(I also changed the Title, Description, and Author tags -- do whatever you want with those.)

Then, in SSMS, I used Tools -> Code Snippets Manager to import the new snippet. Now, with My_column_name selected in a query window, I can use Ctrl+K, Ctrl+S, Down, Down, Enter, Down, Enter to apply the new snippet.

It's not a single keystroke, but it's heading in that direction. Maybe this will inspire someone else who can make it even better.

like image 171
Doug Deden Avatar answered Nov 20 '25 06:11

Doug Deden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!