Results 1 to 7 of 7

Thread: Runtime 'IN' Condition

  1. #1
    Join Date
    Apr 2006
    Posts
    4

    Runtime 'IN' Condition

    Hi,

    I need to specify the IN condition for an SQL during runtime.
    The other part of the SQL is static.

    However, doing the below doesn't even seem to work.

    SELECT * FROM users
    WHERE login IN ('user1' || ',' || 'user2')

    The string "'user1' || ',' || 'user2'" is built and set during runtime.

    Anyone has any idea why it doesn't work.
    Please advise.

    Thanks.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Which rdbms do you use?

  3. #3
    Join Date
    Apr 2006
    Posts
    4
    I had tried with Informix, DB2 and MS-SQL.
    All seem to have the same problems.

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    In ms sql, you should use dynamic sql for that.

  5. #5
    Join Date
    Dec 2004
    Posts
    502
    What is the "||" used for? In mssql, that won't mean anything, so your end result should look like this:

    SELECT * FROM users
    WHERE login IN ('user1', 'user2')

  6. #6
    Join Date
    Apr 2006
    Posts
    4
    Hi rmiao,

    Yeah, for MS-SQL we can use dynamic SQL.
    But for DB like Informix, it doesn't support dynamic SQL and we have to use ESQL.

    I'm developing a system which might be using different databases for each client. So, actually, I'm trying to look for a more generic solution rather than doing ESQL, etc.

    For that, I wish to understand why that particular SQL won't work. If we pass 'user1' || '', it would still work (it's a run-time string as well).


    Thanks.

  7. #7
    Join Date
    Apr 2006
    Posts
    4
    Hi nosepicker,

    I'm just trying to simplify the SQL for my posting.
    For MS-SQL, it would be:

    SELECT * FROM users
    WHERE login IN ('user1' + ',' + 'user2')
    --> user1, user2

    or

    SELECT * FROM users
    WHERE login IN ("'user1'" + ',' + "'user2'")
    ==> 'user1', 'user2'

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •