trying to create a table function that returns a two column table that must be conditioned with an if statement.
I have two other functions that do this separate but cant get it to work when combined.
create  function dbo.PDM_GetCategorytable (@Mystring varchar(200) ,@appid int)
returns table
as -- begin
--return
begin
-- declare @MyString varchar(200);
--set @MyString= 'Fred mtf is dead'--'RE: [Encrypt]]FW: MTF Military --- 
--UPDATE URGENT'
--declare @AppId int =5
declare @Dubb Table (Col varchar(200));
insert into @dubb 
(Col )
values ( @Mystring);
if ((select top 1 categoryid from @dubb a
left join 
(SELECT        (pass.Recordid) as categoryid , pass.appid, 
pass.Priority_Identifier, pass.PrioritySortorder, pass.Category, 
ps.Search_String AS SrchVar
FROM            dbo.PDM_PriorityAssignments AS pass INNER JOIN
                     dbo.PDM_Priority_Search AS ps ON pass.Recordid = 
ps.PriorityAssignmentid where pass.appid=@AppId )  b on a.col like '%' + 
b.SrchVar + '%'
                     order by PrioritySortorder)  is not null)--'where 
appid=@AppId
begin
select top 1 categoryid,Category from @dubb a
left join 
(SELECT        (pass.Recordid) as categoryid , pass.appid, 
pass.Priority_Identifier, pass.PrioritySortorder, pass.Category, 
ps.Search_String AS SrchVar
FROM            dbo.PDM_PriorityAssignments AS pass INNER JOIN
                         dbo.PDM_Priority_Search AS ps ON pass.Recordid = 
ps.PriorityAssignmentid where pass.appid=@AppId )  b on a.col like '%' + 
b.SrchVar + '%'
                         order by PrioritySortorder;
                    end
else
begin
select recordid as categoryid,Category  FROM dbo.PDM_PriorityAssignments 
AS pass  where appid=@AppId and Priority_Identifier like 'Routine'
end
return
end;
expected results will be the returning of two columns , category id, and category.
 
     
     
    