Greetings once again SQL friends,Consider the following test data:if object_id('tempdb..#VehMakeVehModel') > 0drop table #VehMakeVehModelcreate table #VehMakeVehModel (VehModelId int, VehMake varchar(100), VehModel varchar(100), EngineCC int, NumberOfDoors int, VehFuelType char(1), VehTransmission char(1), ManufacturedFrom int, ManufacturedTo int)insert into #VehMakeVehModelselect 1, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, 'D', 'M', 2006, 2007 union allselect 2, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 4, 'D', 'M', 2006, 2007 union allselect 3, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 4, 'D', 'A', 2006, 2007 union allselect 4, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, 'D', 'A', 2006, 2007 union allselect 5, 'ALFA ROMEO', '200 LUSSO JTDM (200)', 2500, 4, 'P', 'M', 2006, 2006 union allselect 6, 'VOLKSWAGEN', 'POLO', 2500, 3, 'P', 'M', 2002, 2006 union allselect 7, 'VOLKSWAGEN', 'POLO', 2500, 4, 'P', 'M', 2002, 2006if object_id('tempdb..#MyStagingTable') > 0drop table #MyStagingTablecreate table #MyStagingTable (VehModelId int, VehMake varchar(100), Vehmodel varchar(100), EngineCC int, NumberOfDoors int, VehFuelType char(1), VehTransmission char(1), ManufacturedFrom int, ManufacturedTo int)insert into #MyStagingTable(VehMake, Vehmodel, EngineCC, NumberOfDoors, VehFuelType, VehTransmission, ManufacturedFrom , ManufacturedTo)select 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, null, null, 2006, 2007 union allselect 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, null, 'A', 2006, 2007 union allselect 'ALFA ROMEO', '200 LUSSO JTDM (200)', 1000, 5, null, null, 2006, 2006 union allselect 'VOLKSWAGEN', 'POLO', 2500, 4, 'P', 'M', 2002, 2006select * from #VehMakeVehModelselect * from #MyStagingTableWhat we have is two tables and the idea is to populate the VehModelId in the MyStagingTable table by finding the best match in the VehMakeVehModel table.Now if we look at the very first record in MyStagingTable table we can see that we only have NumberOfDoors, ManufacturedTo and ManufacturedFrom fields. In the VehMakeVehModel there are 5 ALFA ROMEO cars but only two have 5 doors but they have different transmission types (one is Automatic and the other is Manual). As you can see, it's impossible to decide which of these two matches our model so we can not assign an ID. That's perfectly fine.Now the next record in #MyStagingTable has NumberOfDoors AND also a Transmission type but no FuelType. In #VehMakeVehModel we can see that VehModeld 5 is a good match and since there is only record that has NumberOfDoors = 5 and Transmission = 'A', we can safely assume that it's the same model even though we have no fuel type.Next we have another ALFA ROMEO but a slightly different model. This one has only number of doors but in #VehMakeVehModel there is only ONE record with the same model name so we will assume that they are the same models.Finally we have a VOLKSWAGEN POLO and we can see that there is a straight match with the record in #VehMakeVehModel so we can also assign an ID.If that makes sense so far, my question is how can I do develop a single SQL query to do this?!I have done some SQL for this but for the life of me I can't do this in one query or even two.Your help would be much appreciated.Sorry I forgot to add, the following is the desired output:if object_id('tempdb..#MyStagingTable_Outcome') > 0drop table #MyStagingTable_Outcomecreate table #MyStagingTable_Outcome (VehModelId int, VehMake varchar(100), Vehmodel varchar(100), EngineCC int, NumberOfDoors int, VehFuelType char(1), VehTransmission char(1), ManufacturedFrom int, ManufacturedTo int)insert into #MyStagingTable_Outcome(VehModelId, VehMake, Vehmodel, EngineCC, NumberOfDoors, VehFuelType, VehTransmission, ManufacturedFrom , ManufacturedTo)select null, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, null, null, 2006, 2007 union allselect 4, 'ALFA ROMEO', '159 LUSSO JTDM (200)', 2387, 5, null, 'A', 2006, 2007 union allselect 5, 'ALFA ROMEO', '200 LUSSO JTDM (200)', 1000, 5, null, null, 2006, 2006 union allselect 7, 'VOLKSWAGEN', 'POLO', 2500, 4, 'P', 'M', 2002, 2006select * from #MyStagingTable_Outcome |