so... yeah... I took a guess at what you where trying to do... (you could have been clearer if you had posted some sample data to work with
)anyway, this is what I came up with:Create Table #Printer (Id int not null)Insert Into #Printer Select 1 Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5Create Table #Feature (Id int identity(1,1), name varchar(100), Printer_Id int)Insert Into #FeatureSelect A.name, Printer_Id = B.Id From (Select Name='Network' Union All Select Name='Print') ACross Join #Printer BCreate Table #Setting (Id int identity(1,1), name varchar(100), value varchar(100), Feature_Id int)Insert Into #SettingSelect A.Name, Value = null, Feature_Id = B.IdFrom ( Select Name='IpAddress' Union All Select Name='HostName' Union All Select Name='Contact' Union All Select Name='Location' ) ACross Join #Feature BWhere B.name = 'Network'Union AllSelect A.Name, Value = null, Feature_Id = B.IdFrom ( Select Name='pageCount' ) ACross Join #Feature BWhere B.name = 'Print'Update #Setting Set Value = '192.168.0.1' From #Setting Where Id = 1Update #Setting Set Value = 'myHostName' From #Setting Where Id = 2Update #Setting Set Value = 'myContact' From #Setting Where Id = 3Update #Setting Set Value = 'myLocation' From #Setting Where Id = 4Update #Setting Set Value = '1' From #Setting Where Id = 21Delete From #Setting Where Feature_Id between 3 and 6Update #Setting Set Value = '192.168.0.1' From #Setting Where Id = 13Update #Setting Set Value = 'myHostName' From #Setting Where Id = 14Delete From #Setting Where Id = 15Update #Setting Set Value = 'myLocation' From #Setting Where Id = 16Update #Setting Set Value = '1' From #Setting Where Id = 24Update #Setting Set Value = '192.168.0.3' From #Setting Where Id = 17Update #Setting Set Value = 'yourHostName' From #Setting Where Id = 18Update #Setting Set Value = 'yourContact' From #Setting Where Id = 19Update #Setting Set Value = 'yourLocation' From #Setting Where Id = 20Update #Setting Set Value = '1' From #Setting Where Id = 25--Select * From #Printer--Select * From #Feature--Select * From #Setting Select Printer=A.Id, MatchCnt = count(*) From #Printer A Inner Join #Feature B On A.Id = B.Printer_Id Inner Join #Setting C On B.Id = C.Feature_Id Where (B.name='Network' AND C.name='IpAddress' AND C.value='192.168.0.1') or (B.name='Network' AND C.name='HostName' AND C.value='myHostName') or (B.name='Network' AND C.name='Contact' AND C.value='myContact') or (B.name='Network' AND C.name='Location' AND C.value='myLocation') or (B.name='Print' AND C.name='pageCount' AND C.value='1') Group By A.Id Having count(*)=5 --(# of conditions... comment out to see matches sorted by closeness) Order By count(*) descDrop Table #PrinterDrop Table #FeatureDrop Table #Setting
Corey
Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."