I assume you are joining on OffenseNo?? What happens if there is more than 1 matching record? You could try a CTE
create table #Temp(
OffenseNo int,
Type char(1),
RepOfficer varchar(30),
Status tinyint
)
Insert into #Temp(OFFENSENO, TYPE, REPOFFICER, STATUS)
values
(100,'1','John Smith', null),
(100,'S','Jane Doe',2)
;With cte1 as
(select OffenseNo, Type, RepOfficer, Status
from #Temp
where Type = '1'),
cte2 as
(select OffenseNo, Type, RepOfficer, Status
from #Temp
where Type = 'S'
and Status = 2)
select *
from cte1 c
join cte2 c2
on c.OffenseNo = c2.OffenseNo
I am querying only from this table, but OFFENSENO is the foreign key.There will be several occurrences of the same OFFENSENO, but the other fields will be unique.
Well then I misunderstood what you were trying to do. The solution from @mike01 does the job You "just" have to use the query starting from ";with cte1 as" and replace #temp with your table name.