coalesce
I often need to wrap a column in a coalesce with 0.
It would be swell if there was a feature where I could select a column, then either right click or Keyboard shortcut to have it wrapped in coalesce.
E.g. select the word
personCount
and have it be replaced with
coalesce(personCount,0) as personCount
-
Thomas Franz commented
You can create a snipped (e.g. in0) with the following content:
ISNULL($SELECTEDTEXT$, 0) AS [$SELECTEDTEXT$]In your code mark the column name, press (and release) the Ctrl-Key shortly and type in0 into the small popup menu to select the snippet (often i would be enough)
It would work well, if you have no table alias
SELECT ISNULL(name, 0) AS [name]
and not so well, if you have one (for this reasons I added the square brackets to not break the code, you may want to remove the alias the whole time)
SELECT ISNULL(o.name, 0) AS [o.name]As alternative you could use RegEx and the usual Replace dialog, which would allow you to do this for multiple columns at once