Here are a couple of ways:select x.[desc],case when count(d.id) > 1 then 'True' else 'False' end as Therefrom( select id from x union all select id from y where person = 856) djoin x on x.id = d.idgroup by d.id,x.[desc]drop table dbo.x,dbo.ydrop function dbo.IsThere
ORcreate function dbo.IsThere( @person int, @id int)returns varchar(5)asbegindeclare @result varchar(5)set @result = 'False'if exists(select 1 from dbo.y where person = @person and id = @id)set @result = 'True'return @resultendgoselect [desc], dbo.IsThere(856,id) Therefrom dbo.x