Home Forums SQL Server 2005 T-SQL (SS2K5) find out which record_ids match on 2 fields and not match a third field. RE: find out which record_ids match on 2 fields and not match a third field.

  • Changed query to use #input2

    When I run the query below, I get 44 rows.

    but When I join the 2 tables I only get 14 rows.

    Expecting only have 14 rows in the query

    select A.*,

    Case

    When A.item = B.item and A.I_desc = B.I_desc and A.m_desc = B.m_desc then 'Type 2'

    When A.I_desc = B.I_desc and A.m_desc = B.m_desc then 'Type 1'

    When A.item = B.item and A.m_desc = B.m_desc then 'Type 3'

    Else 'No Match'End as status_flag

    From #input2 A join#input2 B

    OnA.keyitem = b.keyitem

    Order by A.keyitem