We run Dynamics GP, and anybody that's dealt with GP will be familiar with all of its "magic number" columns representing the various enum values inside the application. For example, a reporting query might look something like this:
... WHERE sod.SOPTYPE = 2 AND iv.VCTNMTHD = 3 AND pod.POLNESTA IN (2, 3)
...which is about as far from self-documenting as possible.
At first I had the bright idea of creating a table called 'Enums', filling it with values, and making a scalar wrapper function so you could query like this:
... WHERE sod.SOPTYPE = Enum('Sales Doc Type', 'Order') AND iv.VCTNMTHD = Enum('Valuation Method', 'Average Perpetual') AND pod.POLNESTA IN (Enum('PO Line State', 'Released'), Enum('PO Line State', 'Change Order'))
Of course, that sucked, because the optimizer couldn't see the underlying 'constant' value, and thus made some rather poor choices since it had to make cardinality guesses.
So it needs to be an actual constant value in the code, but I'm not sure if there are any nice features built into SSMS that would make this sort of thing easy. Could I (mis)use code snippets or templates in some way? If we could do some kind of lookup/insertion to make our code look something like this, that would be awesome:
... WHERE sod.SOPTYPE = /*Order*/2 AND iv.VCTNMTHD = /*Average Perpetual*/3 AND pod.POLNESTA IN (/*Released*/2, /*Change Order*/3)
I'm also not opposed to checking out SSMS add-ins.