mardi 3 mai 2016

Select Rows Where Any of Multiple Columns is in Parameter Values

I have multiple columns which store unique, distinct identifiers that can be used interchangeably. I would therefore like to select records where either Col1 or Col2 is equal to any of a number of supplied parameters. I have tried the following, and variations, IE, where Col1 in (?, ?) or Col2 in (?, ?).

SELECT * FROM Table WHERE EXISTS (Col1, Col2) IN (?, ?);

I can currently acheive this using the following, however, it's long and unwieldy, since it repeats ? in (Col1, Col2) for each query I would like to bind.

SELECT * FROM Table WHERE ? in (Col1, Col2) OR ? in (Col1, Col2);

Ultimately, my query may have up to 1000 parameters (all will be unique), so I was wondering if there is any more natural way to do the above query?

Aucun commentaire:

Enregistrer un commentaire