Where clause

  • Hi All,

    I have an issue, Where I have a set of values in the where clause, In those set of values, A few values are tied with other values.

    How do I write where clause for that sitiation.

    Example:

    where abc in (1, 2, 3, 4, 5, 6)

    For these six values abc in (1, 2, 3, 4) should also have cde in (123, 452, 78, 124, 458).

    How do I write a where clause for this?

    Thanks.

  • something like where abc in (5, 6)

    OR (abc in (1, 2, 3, 4) AND cde in (123, 452, 78, 124, 458))



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • It's unclear what you are asking. Could you give a better example of the data in table form.

    ie

    PRINT 'Declare variable table'

    DECLARE @table TABLE

    (id int

    ,a int

    ,b int

    )

    PRINT 'Insert values in the table'

    INSERT INTO @table (id,a,b) values (1,1,123);

    INSERT INTO @table (id,a,b) values (2,2,452);

    INSERT INTO @table (id,a,b) values (3,3,78);

    INSERT INTO @table (id,a,b) values (4,4,124);

    INSERT INTO @table (id,a,b) values (5,5,458);

    INSERT INTO @table (id,a,b) values (6,6,857);

    PRINT 'Test the load'

    SELECT * FROM @table

  • Thanks Lutz, That worked.

    LutzM (7/8/2011)


    something like where abc in (5, 6)

    OR (abc in (1, 2, 3, 4) AND cde in (123, 452, 78, 124, 458))

  • Thanks eccentricDBA,

    Lutz solution explains what my issue was.

    eccentricDBA (7/8/2011)


    It's unclear what you are asking. Could you give a better example of the data in table form.

    ie

    PRINT 'Declare variable table'

    DECLARE @table TABLE

    (id int

    ,a int

    ,b int

    )

    PRINT 'Insert values in the table'

    INSERT INTO @table (id,a,b) values (1,1,123);

    INSERT INTO @table (id,a,b) values (2,2,452);

    INSERT INTO @table (id,a,b) values (3,3,78);

    INSERT INTO @table (id,a,b) values (4,4,124);

    INSERT INTO @table (id,a,b) values (5,5,458);

    INSERT INTO @table (id,a,b) values (6,6,857);

    PRINT 'Test the load'

    SELECT * FROM @table

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply