I have a table whose primary key is claims_id, but for legacy reasons I need to be able to look up records with either of the parameters claims_id or claim_id. How can I achieve this? I’ve used a pattern like the following for search queries before:
select...
where (
{$claims_id} is null
or
claims.claims_id = {$claims_id}
)
and
(
{$claim_id} is null
or
claims.claims_id = {$claim_id}
)
…but this just doesn’t seem quite right to me, as you could provide both parameters to the query, which doesn’t make any sense. What’s the correct way to achieve something like this?
These are large tables, and so if for someone reason neither parameter is specified, the query should return nothing.
Update: Noting that the database in question is DB2.
If it isn’t possible to adjust the broker so that it only allows for the one parameter name, then my recommendation is to have a pre-workflow for the operation which checks for the existence of the two parameters and adjusts them as necessary.
For the most simple example,
Then in the query you would only concern yourself with the claim_id parameter.
This would also allow situations where both parameters are provided to be dealt with or recorded in some manner.