1

I would like to write a query

Select col1, col2 
from table 
where col1 = 'blah' or 'blah2' or 'blah3' 
  and col2 = 'blah' or 'blah2' or 'blah3'

I am used to writing them like this for a SINGLE option

select 
    col1, col2 
from 
    table 
where 
    col1 = :col1 and col2 = :col2

Parameters.AddWithValue(":col1", 'blah')
Parameters.AddWithValue(":col2", 'blah')

Now I want to add several options with OR between them and obviously the above code wont work. The SQL is for SQLite. Can anyone suggest how I could do this? I may potential have more then 3 different values for each parameter. I have tried searching but the answer is elusive.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1500403
  • 551
  • 8
  • 32
  • 1
    You can take a look at [this question and its answers](http://stackoverflow.com/questions/337704/parameterize-an-sql-in-clause). It is for Sql Server but some of the answers are general enough that you can try with SQLite – Steve Oct 11 '15 at 07:46

1 Answers1

3

You still have to use complete expressions, i.e., you need to write col1 = or col2 = every time.

Alternative, use IN:

SELECT ... WHERE col1 IN (:c11, :c12, :c13) AND col2 IN (:c21, :c22, :c23);
CL.
  • 173,858
  • 17
  • 217
  • 259