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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With