mercredi 30 septembre 2015

Sql query with join to return a part number that exists in one table and does not exist in another table with other field data

I'm trying to return data from one table A that does not exist in table B with certain data. For instance:

Table A     No_         Inventory Posting Group
             1           PART
             2           NEW
             3           PART

Table B     No_         Table ID       Dimension Code
             1           27             Branch
             2           27             Manufacturer
             3           27             Department

Every part No_ exists in table A. Table B needs to have both "Branch" and "Department" on a separate row. Some parts have one or the other or both in Table B. I'm trying to return results that show for every part listed in table A which ones are not present for "Branch" and "Department" in table B. It may be two separate queries. Here is what I have now, but I'm not getting what I want.

select dd.[No_], dd.[Table ID], dd.[Dimension Code], dd.[Dimension Value Code], dd.[Value Posting], dd.[Multi Selection Action]
from [Item] i left outer join [Default Dimension] dd

on  i.[No_] = dd.[No_]

where dd.[Dimension Code] not in ('BRANCH', 'DEPARTMENT')
and i.[Inventory Posting Group] = 'PAR'
and dd.[Table ID] = 27

Aucun commentaire:

Enregistrer un commentaire