Support for SQL "in (x,y,z)"?

Performing equality tests and between comparisons is pretty straight forward. Is it possible to use SQL's IN condition without writing dynamic SQL in code? For example,

select * from Table where Field in (1,5,7)

I'm using Unidac or ADO on occasions for data access to SQL Server.

Comments

  • gpigpi
    edited 3:55AM
    wrote:
    Is it possible to use SQL's IN condition without writing dynamic SQL in code?
    No, it's not possible
  • edited 3:55AM
    If your Database Engine syntax allows some sophisticated solutions (like the one I use does) then you may write something like below:

    select * from Table where Field in (select cast(row_value as int) from sa_split_list('1,5,7,8,9'))

    where procedure sa_split_list( string_expression) results a set which contains rows:

    row_numer --- row_value
    1 --- 1
    2 --- 5
    3 --- 7
    4 --- 8
    5 --- 9

    And if you can use such where condition, then you may change it to a form like below:

    select * from Table where Field in (select cast(row_value as int) from sa_split_list( :MyStringParam))

    Mick

Leave a Comment