Not sure about the performance but your query will be better then mine performance wisecreate table #mstcodeparts (co_code int,codeid varchar(50),partid int)insert into #mstcodepartsselect 1, 'QSPPG0038017036', 2 union allselect 1 ,'QTMGR0000030055', 2create table #mstcodification (codeid varchar(50),type varchar(50),range varchar(50))insert into #mstcodificationselect 'QSPPG0038017036','SPPG', '38.17/38.364' union allselect 'QTMGR0000030055 ','BLLI', '0.2' union allselect 'ADAV','TWST' ,'0-60' union allselect 'ADAVI','TPGG', '0-70' select * from #mstcodepartsselect * from #mstcodification--san79select isnull( (select '-1' from #mstcodeparts b where b.codeid=a.codeid and b.partid='2' and b.co_code='1'),'0') as [status] ,a.codeid from #mstcodification a--Ideraselect case when nullif(a.partid,null)IS null then 0 else -1 end as status, b.codeid from #mstcodeparts afull outer join #mstcodification b on a.codeid=b.codeiddrop table #mstcodepartsdrop table #mstcodification
PBUH