I work with a lot of processes that have WHERE clauses that look like this:
WHERE ... AND ( ( myTbl.myValue = 1234) or (myTbl.myValue = 1235) )-- Value = No
I talked about this with some colleagues, and such code seems inevitable. I think it would be nice to put this code in one (and only one) place. It can be a presentation, it can be a table, etc. I am thinking of a view that selects from a base table and has a bit field that says that the value 1234 or 1235 is 0. Or "N", etc. This way, I can add the value "No" without having to change the code. I would not use UDF for this, too many function calls if you use it in a connection.
What other options are there for working with special values ββin your database? Are views a good solution to this? Are there any ways to avoid this kind of thing at all? I think that if this value has to change for any reason, I donβt want to deal with the change of hundreds of processes. On the other hand, an additional connection, so this is a performance hit.
Update: if someone has strategies for just getting rid of the damn things that would be good too. As I said, we talked with colleagues, and this seems inevitable in organizations that have a lot of business logic in the db layer.
PS: I saw a few questions about the magic number, but nothing specific to the database.
source share