Can I convert this common bit of sql into a function?

3 thoughts:

  1. View
  2. Write dynamic sql with any common strings defined in advance and just plugged into the dynamic sql string
  3. Use a text substitution utility as a front end so you can have macro’s etc. (I use one I wrote for myself years ago, I use it for any language and any platform I’m on, kind of handy but not always a standard approach in the business world so you need to be careful about where you use it)