logic needed for the And or OR operation

  • I have the below table.

    Rulesid functiontypeid name nickname nametype

    1 1 abc a null

    1 1 def d null

    1 2 null null complex

    2 1 def d null

    2 2 null null simple

    I need to check the different possible operation with this table.

    RulesID-1

    ---------

    case- 1) The Person name match with (abc) and nick name match with (a) and nametype is complex

    case -2) The Person name type is complex.

    case -3) (The Person name match with (abc) and nick name match with (a)) or ((The Person name match with (def) and nick name match with (d)) or name type is complex.

    similar to this there is different rules for rulesid-2.

    How can I check the different operation with this meta data?

  • Hi ,

    I hope this code meets your requirement

    declare @Temptable table(Rulesid bigint ,

    functiontypeid bigint,

    [name] nvarchar(100),

    nickname nvarchar(100),

    nametype nvarchar(100)

    )

    insert into @Temptable

    select 1, 1, 'abc', 'a', null

    union all

    select 1 ,1, 'def', 'd', null

    union all

    select 1 ,2, null, null, 'complex'

    union all

    select 2 ,1, 'def', 'd', null

    union all

    select 2 ,2, null, null, 'simple'

    --select * from @Temptable

    declare @Case tinyint

    set @Case=1

    SELECT * FROM @Temptable WHERE

    ((@Case=1 AND [name]='abc' and nickname='a' and nametype='complex')

    OR

    (@Case=2 and nametype='complex')

    OR

    (@Case=3 and (([name]='abc' and nickname='a') OR ([name]='def' and nickname='d') OR (nametype='complex')))

    )

Viewing 2 posts - 1 through 1 (of 1 total)

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