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 8:21AM
    wrote:
    Is it possible to use SQL's IN condition without writing dynamic SQL in code?
    No, it's not possible
  • edited 8:21AM
    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

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.